Resize button by text size

Started by AlexxanderX, 21 January 2015, 15:58:35

AlexxanderX

auto buttonCreate = tgui::Button::create(THEME_CONFIG_FILE);
buttonCreate->setText("Create");
buttonCreate->setTextSize(20);


Without setting the size of the button, but by setting the text size the button should calculate the correct size of the button. In the version 0.6 this was working but now doesn't work anymore.

texus

The text size does not change the size of the button. Not even in v0.6.

It only works the other way, by setting the text size to 0 (default), the size of the text is recalculated automatically when the size of the button is changed.

AlexxanderX

So I can't only set the text size without setting the size of the button and the button to automatically set to the right size?

texus

No you can't. You must call button->setSize to give it a size.

There are of course workarounds for what you want, but they are probably not worth the effort. You would be able to create a Label widget (without adding it to the gui) and setting the size and text in it. Then add something like button->setSize(tgui::bindWidth(label) * 1.2f, tgui::bindHeight(label) * 1.2f) somewhere in your code. By changing the text or size of the label, the button will then automatically be resized. But then you have to be updating the text in both the label and button the whole time and you might as well just create a button without text and using the label to display the text.