- Home /
Question by
onuryurdupak · Sep 15, 2016 at 04:20 AM ·
positioninglayoutrecteditor scriptingcentering
Editor Scriping: Centering an element in Rect container
I have been playing around with editor scripting for a while but I can't seem to figure out some aspects of it. For example, I have GUI.Label that shows a text that prints "Conditions" which is displayed in a Rect. How would I align it to the center? Rect.center seems to give the Vector2 value for center of the Rect but I would still require the size of the GUI.Label to make it perfectly centered I guess?
P.S: I am trying to center the text in its yellow container, NOT center the container in editor window.
void OnGUI()
{
Rect conditionsTitle = new Rect(0, 36, 196, 36);
Color yellow = new Color(1, 1, 0);
EditorGUI.DrawRect(conditionsTitle, yellow);
GUI.Label(conditionsTitle, "Conditions", EditorStyles.boldLabel);
}
customeditorwindow.jpg
(7.9 kB)
Comment
I guess I can put "Conditions" GUI.Label inside a manually aligned rect. Then nest it inside the container rect. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612092822im_/https://answers.unity.com/themes/thub/images/avi.jpg)