PDA

View Full Version : Dynamically recentering text


ajones
08-06-2004, 08:26 AM
Hi all, wondering what the best way is to go about recentering a line of text in its parent view after a settext() call.

The text in this area is changeable via our code but always seems to start from the same spot as the original loaded text. We need to keep it centered on every change. Any thoughts? Thanks.

antun
08-06-2004, 09:04 AM
If it's just a single line of text, you can do something like:


<view name="parentView">
<text name="myTextField"
resize="true" align="center" />
</view>


By not explicitly setting the width of myTextField and setting the resize attribute to true the width of the text field will adjust every time the text is set, so the align="center" behavior should happen as expected.

-Antun

PS Try giving myTextField a bgcolor while developing; you'll see the size change.

ajones
08-06-2004, 10:31 AM
D'oh! Can't believe I forgot the resize="true" attribute... on the one tag I needed it- LOL!

ajones
08-09-2004, 01:16 PM
I've noticed this doesn't seem to work with multiline text tags. If the text gets reset to something so long that it needs to wrap, how can I keep both lines center justified?

antun
08-09-2004, 01:24 PM
There's no way of centering multiline text at the moment.

-Antun

SergioGuru
07-26-2005, 04:51 AM
Originally posted by antun

By not explicitly setting the width of myTextField and setting the resize attribute to true the width of the text field will adjust every time the text is set, so the align="center" behavior should happen as expected.



How can text be centered if it's defined as an attribute of a class? If I set those attributes and have text="${classroot.text}" there's no aligning. Even that method in the tutorial (centering button) doesn't help.

Don't bother answering, I've found a solution, thread http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=1560 has helped with me that. For anyone struggling about it, here it goes:

<class ...>
<attribute name="text" type="text" />
...
<text text="${classroot.text}" x="${(parent.width / 2) - (this.getTextWidth() / 2)}" ...>
...
</class>

Of course, it's expected that you have your text node inside a view etc.

Enjoy,
Sergej