[FMX] dynamically resize fonts

Hi all!

I have a dynamic text box of fixed with - lets say 200px wide.
This box will display a user input line - I want the font in the box to dynamically resize so it will fit nicely- if the user types “Cat” the text will be very large (it doesnt have to fit perfect) and if they type “The cat in the hat was a very fine book” the font size would decrease so it will still fit in that 200 px width.

I have found this “TextField.setTextFormat” in the AS dict. but don’t really understand how to pass anything along.

If this is to difficult I will accept making the text multiline - something I also can’t seem to figure out.

Thanks,
Tobias

I’m not very advanced in actionscript but this seemed like a nice assignment for myself. It sort of works but there remain 2 problems:

  • the transistions from fontsize are kind of jagged in the beginning
  • it doesnt allways keep the the text in the box and if that happens the first letters will scroll of the screen
    If anyone would be able to contribute solving these problems im sure tgelston and I would be very gratefull.

Anyway here is my setup, hope it helps you out a bit:


format = new TextFormat();
this.createTextField("blaat", 1, 10, 10, 200, 400);
format.size = 20;
blaat.border = true;
blaat.type = "input";
blaat.onChanged = function() {
	if (blaat.textWidth == 0) {
		format.size = 20;
	} else {
		ratio = blaat._width/blaat.textWidth;
		format.size *= ratio;
		blaat.setTextFormat(format);
	}
};

Great - Thank you!

–Tobias

no problem, but like i said it could work a bit prettier, maybe if you limit the fontsize? the big fonts have rather big intervals