+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.

in Engine by (31 points)

2 Answers

+2 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.

by (3,296 points)
selected by

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.

by (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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.