Nifty: line breaks and text not being aligned right

Hi @all,

I think I need a pointer in the right direction; I have two problems:

  1. Issue - wrong alignment:
    When I change the text in a nifty element like this: <text id=“abc” font=… />,
    it seems like the text does not align in the right way…
    I set it to align=“left” but it looks more like align=“center” to me. At least it is noticeable the text goes WAY over the left border of the panel
    Is there some issue with nifty resetting the alignment values or do I miss something?
    The code in the .xml-file:
    [java]<text id=“inv_description” font=“Interface/Fonts/Default.fnt” color="#ffff" text=“Description” align=“left” valign=“top”/> [/java]
    Resetting the text from the source code:
    [java] nifty.getScreen(“inventory”).findElementByName(“inv_description”).getRenderer(TextRenderer.class).setText(“Very long text here”); [/java]

  2. Issue - no line breaks:
    The text should be used to contain some sort of description of the single items in the inventory, therefore it´s fairly long.
    When testing it out, I saw that NiftyGUI seemingly has no automatic line breaks when the text is longer than the panel.
    Is there some way to do those automatic line breaks?
    I tried to use the TextField but usually the user should not be able to edit this text.

Thanks for giving me hints for either one of the issues!

For your first issue… I believe you are using the wrong alignment tags. I believe those tags align children elements so they wouldn’t work on a text control. There are specific text alignment tags that you would have to look up in the documentation.

I think you can set the “wrap” attribute to true as long as you use a fixed width text control. Its been a long time since I’ve delved into nifty so you might want to check the manual.

1 Like

thank you glh, both of your suggestions were right!
I checked the documentation and for anyone else wondering about those tags, they are:

wrap=“true”
→ the text will make autmatic line breaks if you have specified something like width=“100%”

textHAligned=“left”
→ this is the alignment of the actual text (there is textVAligned too)

thanks again, issue solved!

1 Like

No problem, I’m glad it helped!

1 Like