Skip to main content
stoem
Known Participant
January 19, 2012
Question

How to resize text container efficiently?

  • January 19, 2012
  • 1 reply
  • 3478 views

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

This topic has been closed for replies.

1 reply

stoem
stoemAuthor
Known Participant
January 24, 2012

Some input on this would be greatly appreciated.

Thanks,

Stefan

Participating Frequently
January 29, 2012

Every input should trigger a re-compose of TLF. You'd better listen to the CompositionCompleteEvent.COMPOSITION_COMPLETE to decide if the text is over the boundary.

Why not make the scrollPolicy is on. TLF will automatically make your text to be scrolled.

stoem
stoemAuthor
Known Participant
January 30, 2012

Thanks, I will give that a try.

Unfortunately I cannot use scrolling since the entire text must be visible to the user as one chunk.