PDA

View Full Version : Text Alignment for text based controls



Zeus
April 1st, 2010, 19:08
Hey all,

Quick question:

Does anyone know of a method I can use to right-align text within a stringcontrol.

I can see a tag for centering text
<center /> but not for right aligning text, is this possible ?

Thanks.

Foen
April 2nd, 2010, 05:33
You can't right-align directly, but you can anchor a text control by its right-hand edge and let it size to fit:


<stringcontrol>
<anchored>
<right>
<anchor>right</anchor>
</right>
<top>
<anchor>top</anchor>
</top>
<size>
<height>14</height>
</size>
</anchored>
<static>Some Text</static>
</stringcontrol>

If you specify the right anchor but don't specify a left anchor or the width, the control will assume a size just sufficient to display the text. This makes it appear right-aligned.

Unfortunately this doesn't work with number controls (for left alignment) and nor does it deal with multiline/wrapped text.

Foen

Zeus
April 2nd, 2010, 09:38
Foen - Thanks for the input.

Thats actually what I am doing at present and your right it works well for static based strings. My problem is more about how to handle this for dynamic length stringcontrols i.e. for non-static strings.

For non-static strings I find that unless I anchor both the left and right edges or anchor one edge and define a static width, the text is not always displayed properly or other controls which anchor to the the string control do not display.

I have a bit of a fudged fix in placed for variable length strings which dynamically adjusts the anchored width based upon the length of the string. The only problem is, the set width is not pixel accurate and therefore more of an estimated width as some characters in the fonts I'm using are not equal in size (width).

I end up for some string lengths, with the controls slightly larger than the string, for others spot on, and for the remaining sometimes too small. The result is text which looks left aligned or skewy.

I'm just hoping adding a <right /> tag for text based controls is a something thats quite quick for the Smiteworks devs to add in. It seems criminal that its missing given left and center are in.

Z.

Foen
April 2nd, 2010, 10:00
I also used the technique for non-static strings in the CoC ruleset (NPC/creature type). You're right though, a tag would be useful.