+1 vote

The document says
SIZE_SHRINK_CENTER = 4 — Tells the parent Container to center the node in itself. It centers the Control based on its bounding box, so it doesn’t work with the fill or expand size flags. Use with size_flags_horizontal and size_flags_vertical.

But somehow it is not working for me. Is there anything besides setting this size_flag required for automatic center alignment to work?

I know how to do it manually in the script but it is kind of a pain in the butt to scripting it for every UI component needs this. Especially when I am using a mix of GDscript and GDNative.

asked Feb 25, 2019 in Engine by logicor (30 points)

2 Answers

0 votes
Best answer

I understand that you want to center a control in the editor?
Select "Center" from the layout button (green button above editor window). Which sets the anchor values of the control to 0.5 each.
(Margin values then indicate the distance from each side of the control to the center.)

Alternatively you should be able to set the anchor values to 0.5 in code if you desire.

answered Feb 25, 2019 by wombatstampede (3,185 points)
selected Feb 25, 2019 by logicor

Thanks, that worked very well!

0 votes

You can center control with CenterContainer, Like this
parent-
CenterContainer-
child_item
remember to set the size of CenterContainer as extend mode.

Hope to help.

answered Feb 25, 2019 by att (35 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.