Center align title

For me (Godot 3.4), setting the Label's align property to center doesn't achieve center alignment (and in the video, you have to go back and recenter the text again).  If the text is then later edited or changed, it once again is not centered.

I'm still researching it, but the align property seems to indicate how to handle the text when it is multiline, NOT how it is positioned in the parent?  You can see in this screenshot how using the "Layout Center Top" has merely adjusted the Margins such that the text (when it was "Title") is centered, but any dynamic text will lose this.

To fix this, and achieve what I normally think of as centered text, I had to change the horizontal grow direction from the default "End" to "Both".  Then the text stays centered, regardless of what length text is provided.

Is this how it should be handled?

  • Nathan Lovato replied

    What you did works so you don't have to worry for this title. In general, it's easier to use the align option.

    Here's why the Align option seems to have no effect for you: it aligns the text within the node's bounding box (the orange rectangle). As in your image, the bounding box is only as big as the text, you can't see the alignment in action.

    You'd want to resize the bounding box with the select tool (Q) to see the text center in its box.

    The Grow Direction options control how the bounding box of a UI node grows when its content changes. Often, for text, you don't want the box to grow.

    Think of things like a dialogue box: you don't want your text to overflow outside the dialogue box's background. This is why for text we tend to favor using the align, wrapping, and other options.

  • R
    RealityStop replied

    That makes perfect sense, thanks!