- Home /
Getting GUILayout.BeginHorizontal() to wrap?
Hi,
I have a couple of buttons organized with begin horizontal but the problem is how do you get them to wrap around and start on the next line once they have hit the max width of declared in GUILayout.BeginArea?
The code below I have is my attempt at it but I get ArgumentException:GUILayout:Mismatched LayoutGroup.Repaint
But I dont think this is a good way about it anyway so does anyone have any suggestions? Really stumped...
void OnGUI() {
float width = 200;
// Wrap everything in the designated GUI Area
GUILayout.BeginArea(new Rect(Screen.width / 4 - 50, Screen.height - 300, width, 700));
// Begin the singular Vertical Group
GUILayout.BeginVertical();
GUILayout.Label("REPORT HEADER");
float w = 0;
GUILayout.BeginHorizontal();
for (int i = 0; i < workSearchRef.workWordArray.Length; i++)
{
string word = workSearchRef.workWordArray[i].word;
if (workSearchRef.workWordArray[i].isTarget)
{
if (GUILayout.Button(" " + word, Highlight))
{
print("button pressed");
}
}
else
{
GUILayout.Button(" " + word, Normal);
}
Rect rect = GUILayoutUtility.GetLastRect();
w += rect.width;
if (w >= width)
{
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
w = 0;
}
}
GUILayout.EndHorizontal();
if (GUILayout.Button("Close"))
{
chairRef.closeWork();
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
Answer by Dunkelheit · Jun 07, 2016 at 03:44 AM
Try to use EditorGUIUtility.currentViewWidth
to get the with of inspector zone and calculate how many buttons (if you know each button's size) will be supported each row.
Make sure you're using it inside an OnInspectorGUI() or some else wrapped method called inside it.
Your answer
Follow this Question
Related Questions
Aligning an overlay to existing GUI elements 0 Answers
Open gui if player clicks on button 2 Answers
Help w/GUILayout Please 1 Answer
Guilayout problems with image resize 0 Answers
Help with GUILayout and tooltip(C#) 1 Answer