Topic was automatically imported from the old Question2Answer platform.
Asked By
Adham
Old Version
Published before Godot 3 was released.
I have a control (a container) that I am instancing buttons into (as children) & out.
When I add a button, the control resizes automatically to increase in size & fit that button.
However, when I remove a button the control stays the same large size & doesn’t shrink to fit the existing buttons again.
I tried making it shrink back by saving the buttons’ info, deleting the control, creating a new one, then adding the buttons back with their info so it appears the control has shrunk. This is very ineffective, and there must be a better way to do it.
There doesn’t seem to be a refresh() or redraw() function that would do fit the size back .
I am having the same problem with a GridContainer and emitting the “resized” signal (and every other signal i thought might trigger a refresh) doesn’t work.
I am currently stuck at this, so any more ideas ?
You can set the size of the container to the minimum size to have a resize function.
Here is a recursive solution which will resize all children container to its minimum size.
func _resize_container(container):
for child in container.get_children():
if child extends Container:
_resize_container(child)
container.set_size(container.get_minimum_size())
I’m experiencing the same when reducing text size. In my case the parent container does not resize itself. It does grow, but it does not shrink.
I have seen that the Control does resize itself correctly if I hide it and show it in the inspector, and also from code (even without waiting for the next frame).
I’m hence using the following workaround:
text.Text = step.text;
textContainer.Visible = true;
// Worksaround text panel not shrinking
textContainer.Visible = false;
textContainer.Visible = true;