Problem with Bind and setAutoSize
« 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->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.

In the image "Get Ready!!!" is the label.

Any ideas? The width is changing correctly but that doesn't seem to affect the binding.



  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Problem with Bind and setAutoSize
« Reply #1 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 (which will eventually be released as v0.7.5) and build that TGUI version yourself with cmake.
« Last Edit: 12 June 2017, 14:05:16 by texus »

Re: Problem with Bind and setAutoSize
« Reply #2 on: 13 June 2017, 00:43:22 »
Perfect, thanks!