center align in labels

Started by billarhos, 12 May 2018, 11:06:25


Hi Texus.

The center alignment when more than one lines exist, in my case in "buttons" but i can think that the same happening in "labels" also since "buttons" uses "labels", has not
correct align. All lines keep the first line start position. But each line has different count of chars.

It would be great if this would be implement at least in the new version of tgui. This, it would give me an extra motivation to start using 0.8 version sooner ;)



Labels already supports this, if they are given a size (via setSize) then you can use "label->setHorizontalAlignment(Label::HorizontalAlignment::Center)" to center the text. Widgets don't use labels internally anymore for performance reasons, the needed functionality was moved to a Text class (which Label also uses). But this text class if only meant to contain one line, the multi-line text and alignment are implemented directly in Label.

Buttons weren't supposed to have multiple lines of text on them.
At least it is already possible to create an empty button, put a label in front of it and call label->ignoreMouseEvents() to let clicks on the label reach the button.


Ok,  i downloaded 0.8 and saw that buttons now using text. Just to clarify, lines in labels in 0.8 version keep center align accordingly to each line chars?

For example is it like this?
       Line 1
     My line 2
Ok this is line 3

There are a lot of cases when translating a text from one language to another, texts can be much bigger. Setting auto the size can do the trick but the text can be
not-readable. In my case this is happening in button text very often.


QuoteJust to clarify, lines in labels in 0.8 version keep center align accordingly to each line chars?
Yes, each line will be centered individually.


Ok Texus thats great.
Talking about performance, have u made any performance test between 0.7 and 0.8 versions?


No, but I wouldn't be surprised if 0.8 was slower than 0.7 in some parts. Performance has never been an important factor so I don't measure it when making changes.
The performance difference I talk about with labels was about some widgets being completely unusable. Like how adding 500 lines to a ListBox required creating 500 labels (and creating widgets is rather slow), making it completely unusable. Most of these cases (like ListBox) where already solved in 0.7 though, but in 0.8 I unified the code in a Text class instead of having duplicate code in all these places where I stopped using labels.