- Home /
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:
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?
Answer by dai1741 · Sep 28, 2011 at 05:36 PM
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));
Answer by CaJerry87 · Dec 20, 2016 at 07:45 AM
This is probably you should check out, its about Custom Inspector Layouts http://answers.unity3d.com/answers/1288008/view.html
Your answer
Follow this Question
Related Questions
GUILayout.Buttons overlap but only can click the bottom one 0 Answers
GUILayout.BeginHorizontal with a visual border/background? 3 Answers
Spawning an object on the opposite side of an activator object with no overlaps 1 Answer
GUILayout margin bug? 2 Answers
How to place an object near N number of objects in order to avoid overlap? 0 Answers