Size flags Fill and Expand

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

Hi,

Haven’t found information about the meaning of Fill and Expand in controls for godot. Could anyone with more experience please explain what are they used too?

I have set a panel and a text label inside, have set the label size flag to expand expecting it to horizontally cover all panel but it does nothing. On the other hand it seems that Fill + Expand can be combined. I’m a bit lost here.

Could anyone help on this?

Cheers.

:bust_in_silhouette: Reply From: razvanc

Yes, those seem to be undocumented. After playing with them this is what I gathered:

  • expand: the node will take as much space as possible. If there are multiple nodes set to expand the available space will be divided equally among them.
  • fill: is mostly relevant if expand is on and it will stretch the bounds of the child node to fill the available space. With fill off and expand on, the node still takes the whole space available, but it’s bounds aren’t modified, the size of the node will be the minimum possible. So basically expand without fill seems to place the node in the center on the selected axis (horizontal, vertical)

Hope the image helps a bit, it’s kind of difficult to explain :slight_smile:

I couldn’t attach the iamge, here’s the link: Imgur: The magic of the Internet

:bust_in_silhouette: Reply From: aftamat4ik

it’s undocumented, but if you want to set this flags from code use this:

line_edit.size_flags_horizontal += SIZE_EXPAND

it’s somehow overload this two operations += and -=
in case if you want to remove flag:

line_edit.size_flags_horizontal -= SIZE_FILL

but for example this will not work:

line_edit.size_flags_horizontal = SIZE_FILL + SIZE_EXPAND

because both enums are basically int values - you can’t feed resulting int as input. It overloads only += and -= operations in gdscript so use them as i shown on top.
Same works for size_flags_vertical.

This is not good advice, it is fundamentally wrong.

It “works” in the narrow and specific cases shown (and with initial value of 0, and if you do it only once).

The Those values are binary flags, also called bit masks or bit fields.
They must be set, unset and checked with boolean operators.

See whole explanation on this wikipedia article

In short, you commonly:

  • Use OR to combine the flags and/or set them

  • Use AND with the inverted flag value (NOT) to unset

  • Use AND with the flag value and check the result is equal to the flag value to check

Gerard Ruiz | 2023-04-13 16:51