0 votes

In a game I'm developing, I have an action bar which contains a fixed number of buttons and a section where I want to add (or remove) buttons depending on whether an action can be executed at the moment. The bar should expand or contract depending on the number of buttons it contains. So at one moment it might have only two buttons, another moment five, but in all cases, the container should expand. I should mention that this action bar has a background (it's a panel at the moment) which should also contract or expand.

By default it looks like this:
enter image description here

If I add buttons, right now it looks like this:
enter image description here
As I'm using a VBoxContainer, it just expands to the right, but I want the background Panel to expand too.

This is how I would like it to look (changed size by hand now)
enter image description here

I took a look at the container section of the documentation, and played a bit in the editor, but all I found is how to make the contained elements change size, but not how the container itself could react to its children by changing size. Is this even possible with the standard containers and controls? I want to know that I'm not missing on anything, before trying to implement my own solution.

Godot version 4.0-beta6
in Engine by (37 points)

1 Answer

+1 vote
Best answer

Unfortunately Godot's container nodes lack an easy way to resize them dynamically, only ways to resize and resort their children. I've encountered this before but couldn't find many native solutions.

The only way I've managed to change the content within a container is by changing the child's visibility. I'd suggest using the .hide() and .show() methods rather than visible = true for readability.


func expand():
by (90 points)
selected by

Thanks! At least I will now stop looking for such a solution, and in case I really need it, will try to implement something myself.

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.