How can I replicate HTML's flexbox in Godot 4?

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

I wanted something like this:

HBoxContainer
  TextureRect
  Label

With the hierarcy above, I wanted to set the TextureRect’s size on my own, not by the HBoxContainer. But I also want to use the HBoxContainer’s behavior to layout it’s children horizontally.

In other words, the TextureRect should have a fixed transform size of (40, 40) and the Label size is dynamically sized based on it’s text content. Just like flexbox in HTML, the parent size should match it’s childrens.

:bust_in_silhouette: Reply From: exuin

Set TextureRect custom_minimum_size and size flags to shrink.

:bust_in_silhouette: Reply From: citizenl

Here is a repository capable of layout using flexbox
github repo here