The largest Button with an icon in a VBoxContainer is not large enough to display the icon

Godot Version

4.5

Question

I am making a context menu using a Control as root that has a VBoxContainer which contains a few buttons that have icons (stored as SVG). To avoid aliasing, those icons are scaled bigger than they should be, so I have to check the “Expand Icon” option to have them at the right size.

However, when the menu appears, the largest button always has its icon completely hidden. I tried forcing sizes on the buttons, the VBoxContainer and the root but even when using custom_minimum_size, nothing actually changes. Or rather, it does but the changes are discarded the next frame, without emitting resized (at least for the buttons).

This can be reproduced using a minimal setup: a main node for the window, a Control, a VBoxContainer, and two Button nodes with different text length, and the Godot SVG for the icon.

What am I doing wrong? Is this a bug?

Hi,

I think this might be expected behaviour, from the doco on expand_icon:

When enabled, the button’s icon will expand/shrink to fit the button’s size while keeping its aspect.

Nothing to say it wont shrink to 0.

Not entirely sure how you should go about fixing it, sizing the SVG appropriately and not using expand_icon would probably be the easiest, else maybe giving the vbox a minimum width that will accommodate all and having the buttons expand to fill, but that may not be viable if you are dealing with dynamic text.

1 Like

This is correct, but I think it should be added to the documentation as it’s not very intuitive, despite being logical.

Regardless, it is possible to make it dynamic. In the Button’s _ready(), adding custom_minimum_size.x = size.x + icon.get_size().x does the job.

Thank you!

The beauty of the open source project is that you can contribute yourself. So if you think it should be added, open a PR or leave a comment at the bottom of the relevant documentation page.