GUI - Equally spaces buttons

Is there a way to equally space buttons without defining a width? They size themselves with the text the contain. Thanks.

GUI.Toolbar probably or maybe automatic layout mode Unity - Manual: IMGUI Layout Modes

GUILayout, but it has a performance hit. However, eDriven framework provides it (free edition here).

You could use normal GUI.Buttons for this and set the size with the string size… pretty simple, just use string.length+10 oder so for the button width, if you store that in another variable or make some more math you can easily place them in equally space on the screen :wink:

Thank you. I’ll look into eDriven.

You can also use GUIStyle.CalcSize to measure your button text before displaying.

1 Like

The easy solution was to include an integer width variable and divide by the number of buttons.

if(GUILayout.Button ("First Person",GUILayout.Width(width/3)))

The reason I didn’t want to include the GUILayout.Width, is I have different number button in different parts of the GUI. I was having to fine tune each of the button widths to match an overall width of the GUI, taking into account the buffer and everything. This spaces them evenly and the text doesn’t control the width.