HBox expands its own size rather than shrinking it's children

Godot Version

v4.3.stable.official [77dcf97d8]

Question

I have a scene with a somewhat complex node hierarchy. One of the nodes is an HBoxContainer which holds several TextRects. Now, for some reason, when enough TextRects are added to the HBoxContainer, the container expands beyond it’s initial size and makes the parent containers expand too.

Why does this happen? I would expect the container to keep it’s size and shrink it’s children instead.

I believe this is a natural consequence of how the containers work. There is a minimum size, but not a maximum size property.
You should be able to use your HUD script to make sure that container sizes do not exceed your preferred values. You may also see if the addon Extra GUI Controls, which includes a MaxSizeContainer node addition, works to your liking for keeping node sizes under control.

TextureRect does not resize automatically unless you change its TextureRect.expand_mode property to anything but Keep Size. You can control how it stretches with TextureRect.stretch_mode

You may also want to give it a Control.custom_minimum_size

Yes, I’ve been playing around with stretch_mode, expand_mode, and the size_flags. No combination seems to do what I want.