Hi forum, It seems I could need some help to understand what SizeFlags is actually suppose to do.
I have a control node, whose single child is a VBoxContainer. I would like this child to have a size equal to its parent, so my understanding was I could achieve it by:
var container = GetNode<VBoxContainer>("VBoxContainer");
container.SizeFlagsHorizontal = (int)SizeFlags.Expand;
container.SizeFlagsVertical = (int)SizeFlags.Expand;
Problem: it just does not work. My root is sized 1000x500, the container stays at 40x40.
So I have 3 questions: Why is it not the case? How can I get this behavior? * and bonus question, what is the difference between Expand and Fill ? ( according to the doc, Fill takes all available space without pushing other nodes, Expand takes all the space and push other nodes, so ExpandFill does what exactly ? )
Thanks a lot for some hints!
PS: here is my minimal example.
[gd_scene load_steps=2 format=2]
[ext_resource path="res://TestScene.cs" type="Script" id=1]
[node name="TestScene" type="Container"]
margin_right = 40.0
margin_bottom = 40.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_right = 40.0
margin_bottom = 40.0
using Godot;
using System;
public class TestScene : Container
{
public override void _Ready()
{
this.RectMinSize = new Vector2(1000,500);
var container = GetNode<VBoxContainer>("VBoxContainer");
container.SizeFlagsHorizontal = (int)SizeFlags.Fill;
container.SizeFlagsVertical = (int)SizeFlags.Fill;
container.AddChild( new Label() );
}
int frameId = 0;
public override void _Process(float delta)
{
frameId += 1;
if (frameId == 100) // make sure cntainer add time to resize
{
var container = GetNode<VBoxContainer>("VBoxContainer");
GD.Print("container size " + container.RectSize);
var parent = container.GetParent() as Control;
GD.Print("parent size " + parent.RectSize);
}
}
}