- Home /
Equally spacing columns in GUI
How can I ensure that the following three buttons are equal in width (give or take a few pixels) whilst stretching to fit the width of their container?
GUILayout.BeginHorizontal();
if (GUILayout.Button("All")) { ... }
if (GUILayout.Button("None")) { ... }
if (GUILayout.Button("Invert")) { ... }
GUILayout.EndHorizontal();
Answer by ScroodgeM · Jul 22, 2012 at 06:49 AM
GUILayout.Button("A Button with fixed width", GUILayout.Width(300));
http://docs.unity3d.com/Documentation/ScriptReference/GUILayout.Width.html?from=GUILayoutOption
In this scenario fixed width doesn't really work for me because when a vertical scrollbar appears (in outer scroll view) a horizontal scrollbar must appear also because buttons are out-of-view horizontally.
Unless, is there a way to get the width inside the current scroll view? (like Screen.width
except for scroll view)
the scrollView's width is it's outer width $$anonymous$$us it's vertical scrollBar's width (depends on GUI style)
The outer width is Screen.width - x
where x
is unknown...
Hmm, might be possible with EditorGUILayout.BeginHorizontal
because it returns its Rect
before rendering the buttons (whereas GetLastRect
is after. Thanks I will give this a go :-)
Your answer
![](https://koobas.hobune.stream/wayback/20220613074526im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Custom Editor GUI Elements 1 Answer
DragAndDrop EditorGUILayout.Box ? 1 Answer
Unexpected selection state in custom inspector? 1 Answer
EditorGUI elements require minimum size of 24px? 0 Answers
Lining up GUI 1 Answer