TGUI Forum

General Category => Help requests => Topic started by: crdl_pls on 12 June 2017, 05:27:21

Title: Problem with Bind and setAutoSize
Post by: crdl_pls on 12 June 2017, 05:27:21
I'm trying to create a label that will automatically centre itself. I'm attempting to do this:
Code: [Select]
label->setAutoSize(true);
label->setPosition(screenSize.x / 2.f - bindWidth(label)/2.f, YVALUE);

So no matter what I set the text to, in theory, the width should adjust accordingly, and then the position should change based on the width.
However, it seems that bindWidth(label) isn't updating when the length changes, and label has no text value until I change it, bindWidth(label) is always 0.
(https://i.imgur.com/am6BkKj.png)
In the image "Get Ready!!!" is the label.

Any ideas? The width is changing correctly but that doesn't seem to affect the binding.
Title: Re: Problem with Bind and setAutoSize
Post by: texus on 12 June 2017, 14:01:47
This was a bug in TGUI, changing the text did not sent a SizeChanged event to which bindWidth subscribes.
I have fixed this in the latest version. You can download the latest version (https://github.com/texus/TGUI/archive/master.zip) (which will eventually be released as v0.7.5) and build that TGUI version yourself with cmake.
Title: Re: Problem with Bind and setAutoSize
Post by: crdl_pls on 13 June 2017, 00:43:22
Perfect, thanks!