hello, i found a bug in nifty.
if i set text “width” then “align” wont work, it will always be centered regardless of its value.
code :
[xml]<text style=“base_font” text="$textName" align=“left” width="$textWidth" />[/xml]
Text align is always center
Vs :
[xml]
<panel width="$textWidth" childLayout=“horizontal”>
<text style=“base_font” text="$textName" align=“left”/>
</panel>[/xml]
Using jpanel instead of width
sigh
This is the same “issue” we discussed in that other thread. You remember that picture, right:
When you set an explizit size for the text element then you will get an explizit size for the text element. Since the text is probably smaller than the size you set for the text element Nifty needs a way to know how it should align the text INSIDE of the element.
If you take a look at the screenshot above you can see a demonstration of two additional attributes that are being used to control the alignment in that case.
You can think about it in this way:
- the align=“left” or valign=“top” alignment properties control the alignment of the element in respect to other elements
- the textHAlign="" and textVAlign="" properties are used to control the position of the text inside the text element.
I’m Sorry that Nifty does not work like Swing - but that is by design and not by mistake
Though in this case… I’d argue that it kind of is working like swing. If you have a JLabel in a GridBag you run into similar situations all the time between the JLabel’s alignment and the grid bag cell’s anchor constraint.
Though maybe I’m showing my age by knowing details about grid bag usage.
aaa, i see. I didnt know text had textHAlign, textVAlign attributes. The wiki didn’t mention them.