GUILayout Positioning for SelectionGrids and Buttons

Still figuring out the layout of GUI objects. The task is to make a SelectionGrid (which may have an arbitrary number of rows), and then beneath that, a column of buttons individually aligned. They’re placed in a GUI area comprising the bottom 100 pixels of the screen, and I try to separate them with horizontal and vertical delimiters. However no matter how I try to lay it out, the buttons get overlaid on top of the selection grid, as if BeginHorizontal doesn’t recognize the positioning of the SelectionGrid, whose rect I placed at the top of the GUI area:

Selection Grid and buttons getting overlayed in the same space.

Code below. I left some of the horizontal/vertical delimiters that I’ve tried (to no avail) commented out:


GUILayout.BeginArea(Rect(0,Screen.height-100,Screen.width,100));
GUILayout.BeginVertical();
//GUILayout.BeginHorizontal();
toolbarSelected=GUI.SelectionGrid(Rect(0,0,Screen.width,50),toolbarSelected,toolbarStrings,5);
//GUILayout.EndHorizontal();
for(var bText in buttonTexts){
	//GUILayout.BeginHorizontal();
	if(GUILayout.Button(bText)){
		//bla				
	}
	GUILayout.FlexibleSpace();
	//GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
//GUILayout.FlexibleSpace();
//GUILayout.EndHorizontal();
GUILayout.EndArea();

Are GUI.SelectionGrids and GUI.Toolboxes not considered elements for the layout arrangement of GUILayout.BeginHorizontal and BeginVertical?

2 Answers

2

GUI.SelectionGrid and GUI.Toolbar are ignored by the layout arrangement, because they’re positioned in fixed layout mode.
To use automatic layout, you need to use GUILayout.SelectionGrid like this:

toolbarSelected = GUILayout.SelectionGrid(toolbarSelected, toolbarStrings, 5, GUILayout.Height(50));

This is probably you should check out, its about Custom Inspector Layouts How to clamp EditorGUILayout controls' width ? - Unity Answers