UI only respects constraints on window resize

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Grid Sherman

So I’ve been reading a bunch of posts on here that sound similar to my problem, but none of them seem to be fixing my issue.

In short, I have a VBoxContainer that is filled with buttons dynamically. I repeatedly add N buttons at once, and then remove them all when a button is selected. The buttons use Fill and Expand size flags to fill out the container when added, and they work fine when adding more buttons.

BUT, if I had let’s say 5 buttons shown previously, and then I show 3 buttons afterwards, the container has now expanded vertically slightly and the bottom buttons are cut off.

On the buttons and containers I’ve tried toggling visible, setting rect_size and rect_min_size and resetting it, the only way I can programmatically get this thing to fix itself is by expanding the window by 20 pixels every time and then shrinking it again, but also only after delaying for a fraction of a second. Here’s the fix I’m using:

func refresh_ui():
	OS.set_window_size(Vector2(OS.window_size.x, OS.window_size.y - 20))
	yield(get_tree().create_timer(0.01), "timeout")
	OS.set_window_size(Vector2(OS.window_size.x, OS.window_size.y + 20))

There has to be a more elegant way to fix this - what happens internally when I resize the window? Can I manually call that?

can you maybe share a project that shows the issue?
i’m not sure i understood it

Andrea | 2021-01-02 23:49