Try to use
PanelContainer, as what a container does is organizing its children automatically. If you use
Panel, it won't take care of them.
Here's a sample code for my simple hiearchy:
For testing, simply add / remove a button by pressing action('add') / action('subtract')
onready var hbox_container = $HBoxContainer
# Helper variable
onready var mim_size = rect_size # get initial size when ready
var btn = Button.new()
btn.text = "Button"
var ch = hbox_container.get_child(0)
if ch != null:
rect_size = mim_size
Note that PanelContainer only resizes its rect when it needs to expand, but not when it can shrink. (I guess the dev should add this feature, if I'm not wrong)
So I manually set it to min_size after the button has been hidden.
And you don't necessarily need to do this when handling resize:
you can do:
(the first approach is safer though)