All Questions



How to center Label without MarginContainer?

In the example, we can see that the dialog is nicely centered with a margin on top too. However, I did not see MarginContainer in the tree. How can we achieve that?

Thanks in advance.

  • Nathan Lovato replied

    In which example that´d be exactly? Could you copy paste the screenshot you are referring to here? Because depending on the scene setup the way you do that is different.

    One way would be to use the labels alignment properties to center the text in the node's bounding box.

    Then if it's about centering the label's bounding box horizontally when it is inside a VBoxContainer, you can set its Size Flags -> Horizontal to Shrink Center only.

    That'll make the node squashed horizontally. You then give it a minimum size by changing the Rect -> Min Size property.

    These changes don't give a vertical margin by themselves but they can give you a horizontal one.

    Then, you can select a VBoxContainer and change its Theme Overrides -> Constants -> Separation to add a vertical separation between it's children, effectively adding a vertical margin.

    But in this series, we don't use that property, the vertical spacing is by default.

  • W
    Wira replied

    I've figured out the horizontal one, but the vertical trick with Separation is a neat one.
    This is what I'm looking for. Thank you!