How to have different widths inside a VBoxContainer?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By wombatTurkey
:warning: Old Version Published before Godot 3 was released.

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

:bust_in_silhouette: Reply From: wombatTurkey

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… :stuck_out_tongue: