+7 votes

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 :( .

in Engine by (45 points)

3 Answers

0 votes

Try to use the resized() signal.

by (692 points)

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 ?

+1 vote

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:
by (123 points)
0 votes

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;
by (40 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 Frequently asked questions and 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 [email protected] with your username.