How to resize text container efficiently?
Hi all,
I'm new to TLF and have managed to put together a small test project to try out right-to-left support. Maybe due to the overwhelming number of classes and APIs I am struggling a bit to create the equivalent of an autoresizing text field which grows as the user adds new text to it.
I have a container (a canvas) to which I add my TextFlow. Example:
textFlow = new TextFlow();
textFlow.direction = Direction.RTL;
var p:ParagraphElement = new ParagraphElement();
var s:SpanElement = new SpanElement();
textFlow.addChild(p);
p.addChild(s);
s.text = "وثيقة إثبات صلة القرابة مصدقة من سفارة دولة الإمارات – إذا لم يكن اسم المكفول مدرجاً في جواز سفر";
textFlow.flowComposer.addController(new ContainerController(this, container.width, container.height));
textFlow.flowComposer.updateAllControllers();
This works fine. Now I'd like the user to be able to add more text and grow the canvas container so that it fits the size of the text contained within. What's the best way to do that? Is there an Event I can listen to that informs me once new text has been added? If so, where should I look?
My plan was to then update the container size with logic along this line:
| var controller:ContainerController = textFlow.flowComposer.getControllerAt(0); | |||||||||
| var rec:Rectangle = controller.getContentBounds(); | |||||||||
| _container.width = rec.width; | |||||||||
| _container.height = rec.height; |
| controller.setCompositionSize( _container.width, _container.height ); | |||
| textFlow.flowComposer.updateAllControllers(); |
Am I on the right track here? Unfortunately I cannot use the Spark components in this project since this logic is contained within a custom MX component.
Regards,
Stefan
