- Home /
How to align a toggle box to the right of a custom editor window?
Hi, I'm writing a custom editor window at the moment, and I'm using BeginHorizontal() and EndHorizontal() to put an EditorGUILayout.Foldout() next to an EditorGUILayout.Toggle box. Unfortuantely, when I have these two options following, the toggle box is aligned to the middle of the editor window, even when resizing the window. Is there a way to get the toggle box aligned to the right of the editor window?
I've tried using a custom GUIStyle, which changes the text alignment, as well as the amount of right padding, hoping that might work, but no avail, it simply makes the toggle box disappear completely.
Answer by ScroodgeM · Jul 24, 2012 at 07:17 AM
make
GUILayout.FlexibleSpace();before toggle inside horizontal block
Unfortunately this doesn't seem to work for me. Here's the UI code for what I'm doing at the moment:
EditorGUILayout.BeginHorizontal();
foldoutActive = EditorGUILayout.Foldout(foldoutActive, foldoutID + " " + foldoutName);
GUILayout.FlexibleSpace(); toggleActive = EditorGUILayout.Toggle(toggleActive);
EditorGUILayout.EndHorizontal();
I believe I need to use GUILayout.BeginArea for flexible space to work, like in the example for the function in Unity Scripting Reference?
Turns out the toggle had a massive amount of white space to the right of it, which caused it to end up way out of place. Just used GUILayout.width(15), which got rid of all the white space. Thanks for the help though Scroodge!
Answer by CaJerry87 · Dec 20, 2016 at 07:45 AM
No No No, read my answer on http://answers.unity3d.com/answers/1288008/view.html on "HOW TO ADJUST THE SIZE OF YOUR BEGINHORIZONTAL/VERTICAL"...it should answer it all.
Answer by SplunkyDev · Sep 28, 2020 at 10:47 AM
ScroodgeM's solution worked for me, the aligned image is with GUILayout.FlexibleSpace(); and unaligned image is without it