0 votes

How can I make an OptionButton always occupy the size of its largest item?

Otherwise I have the following situation, where the GridContainer always resizes on item changes.

Godot version 3.3
in Engine by (38 points)

1 Answer

+1 vote

Figure out the width required to house your largest text option and set that to be rect_min_size.x of that control node.

If you want to do it programmatically, I think you should be able to use Font.get_string_size() to determine the width of your longest text option.

by (2,832 points)

I hoped a cleaner solution existed

You can adjust your rect_min_size values in your editor while your game is running and the changes will take effect in real time. It's pretty quick to create really nice GUIs via the editor utilizing that feature.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.