0 votes

VBoxContainer is wonderful because of its awesome layout positioning which is all automatic (for its children).

The dilemma is all the children added to the VBoxContainer inherit the VBoxContainer's width, not their own. For example what I have here is newly created panels that are added to a VBoxContainer, that disappear after xx seconds:

enter image description here

See how the width changes after each update? That's because I wrote a dirty hack (dont use in production :P):

extends VBoxContainer



func _ready():
    set_process(true)
    pass


func _process(delta):
    for node in get_children():
        node.set_size(Vector2(node.get_custom_minimum_size().width, node.get_custom_minimum_size().height))

Which kind of overrides VBoxContainer's auto width thing, but it looks nasty because of the refresh/update then gets overridden by VBoxContainer's native layout.

So, with all that said is there anyway to maybe take advantage of VBoxContainer's vertical layout feature, but have custom minimum widths? Same could be said for the HBoxContainer too. Thanks in advance

in Engine by (307 points)
edited by

1 Answer

0 votes
Best answer

Wow! I think I just found a solution?

extends VBoxContainer

func _ready():
    pass

func Muffins():
    for node in get_children():
        node.set_size(Vector2(node.get_custom_minimum_size().width, node.get_custom_minimum_size().height))

func _notification(what):
    print("Wow, that was easy. <3 Godot")
    Muffins()

Works great now, no flashing! Helps I think to write my problem out in full then look back... :P

by (307 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.