Why does a Rect within a CenterContainer get (0, 0) for rect_size, but a button does not?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Will Nations

In Godot 3.0, if I create a scene with a CenterContainer, and I set as a child of it ANY type of button, the button will be visible, but putting a Rect under it such as TextureRect or ColorRect will result in it setting the rect_size value to Vector2(0, 0), ergo, it becomes invisible.

I mean, I can create a ToolButton, set its icon to the image I want and set its enabled_focus_mode value to “None”, and that’ll work for me, but what I want to know WHY this is happening.

Anyone know?

:bust_in_silhouette: Reply From: Zylann

When you use Containers, you have to make sure what you put in it has a minimum size, otherwise they will often be shrunk to zero. This is because you cannot define the normal size of controls, since the Container is going to dynamically adjust it (also note the size is also a result of the application of anchors and margins).
Button doesn’t shrink completely because it probably has an internal minimum vertical size of some sort (you will see the width will shrink anyways).

Kind of annoying that we have to setup an explicit minimum size. Do you know if there are plans to eventually setup resizable positions/sizes/scales based on defined percentages, such as “always be 30% as large as the parent Container”.

Will Nations | 2018-02-01 20:49

I believe you can do this by entering numbers between 0 and 1 for the anchors, but if you do it I would advise to not use CenterContainer. You can setup the anchors in such a way they center the control :wink:

Zylann | 2018-02-01 20:50