How to make label width match center container parent

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

I’m struggling to get a label node to match the width of its parent centre container. If I set autowrap to off, it overflows the container. But if I set autowrap to word, it inserts a line break after every space.

I have the centre container set to full rect, and there’s plenty of space for the label to grow horizontally before wrapping.

I’m sure there’s something basic I’m missing, I just can’t figure it out

Have you tried changing the Container Sizing options?

Ertain | 2023-03-17 04:41

I can’t edit the container sizing property on the label, because its controlled by its parent container. And the Center container is set to fill on both H and V.

When I select the label in scene view, you can see its y container size is like 1px wide, but if I select the center container, the y size is full width.

organicpepper | 2023-03-17 21:54

Indeed, the children’s Layout of the CenterContainer node can’t be edited (at least the Container Sizing property can’t be edited). Have you tried using other containers? Maybe use a MarginContainer node?

Ertain | 2023-03-18 00:18

If I nest the Label within a MarginContainer or V/HBoxContainer, I can set the custom_minimum_size of the container to allow it to be full width. However, I feel like this goes against the whole point of using containers to automatically size and place items. I can also set the custom_minimum_size of the label directly to the same effect.

In the tooltip for the custom_minimum_size property, it reads:

If it’s set to (0,0), the node sizes automatically to fit its content, be it a texture or child nodes.

However, this seems to not be happening in this case. With autowrap set off, it seems to be functioning correctly. Is this a bug or intended feature? Perhaps I am not understanding the design philosophy correctly!

organicpepper | 2023-03-20 03:17

Would you like the Label node have a look similar to this?

Ertain | 2023-03-21 02:36