+1 vote

I have a scene setup as the following.

root_node
    center_container
        panel_container
            hbox_container

All 3 containers have 'Shrink Center' as horizontal and vertical size flags.

I dynamically insert other instanced scenes into the hbox_container and also remove them from time to time using script.

My intended behavior is that the panel_container as well as the hbox_container will resize themselves to the smallest possible rect.

It acts as expected when I insert new children, and both panel_container and hbox_container expands to accommodate them. However, when I remove them, they don't shrink back and remain at the last expanded size. Only when I insert new children they change to appropriate size.

How do I force the containers to recalculate size upon removing children?

in Engine by (13 points)

2 Answers

–1 vote

My trick for forcing a control to update itself is to hide() and then immediately show() it. Not sure if that works here, fingers crossed :)

by (629 points)
+1 vote

What seems to work for me is to hide the top level container, that needs to have it's layout recalculated, and then add a deferred call to show it again.

In your case, your top level container of interest is panel_container.

var panel_container = $".".find_node("panel_container")
panel_container.visible = false
panel_container.call_deferred("set_visible", true)
by (16 points)
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.