- Home /
How To Best Match Editor GUI Content Heights
I am making some custom editor design scripts. When laying out things horizontally, I would like all content types to have the same height as the tallest element in the horizontal group. Another way to do it would be to somehow vertically center all elements in the horizontal score.
Here is an image of my problem. As you can see, the button that has an image in it causes the button to expand, so the height of the box no longer looks right.
Here is the code making those controls:
buttonStyle = new GUIStyle("button");
buttonStyle.border = new RectOffset(8, 8, 8, 8);
buttonStyle.margin = new RectOffset(5, 5, 0, 0);
buttonStyle.padding = new RectOffset(5, 5, 6, 6);
buttonStyle.richText = true;
buttonStyle.alignment = TextAnchor.MiddleCenter;
buttonStyle.normal.background = EditorButtonNormal;
buttonStyle.hover.background = EditorButtonNormal;
buttonStyle.active.background = EditorButtonActive;
buttonStyle.normal.textColor = TextColor;
buttonStyle.hover.textColor = TextColor;
boxStyle = new GUIStyle("box");
boxStyle.margin = new RectOffset(5, 5, 4, 4);
boxStyle.padding = new RectOffset(5, 5, 3, 3);
boxStyle.richText = true;
boxStyle.alignment = TextAnchor.MiddleLeft;
boxStyle.normal.textColor = TextColor;
using (var h = new EditorGUILayout.HorizontalScope())
{
if (GUILayout.Button(RkIconCache.Get("d_MoveTool On"), buttonStyle, GUILayout.Width(30)))
{
}
GUILayout.Box("This is my box", boxStyle);
}
using (var h = new EditorGUILayout.HorizontalScope())
{
if (GUILayout.Button("<b>P</b>", buttonStyle, GUILayout.Width(30)))
{
}
GUILayout.Box("This is my box", boxStyle);
}
So I think I'm getting somewhere, but its not quite to my liking yet.
I'm basically just trying to extend the way they handle the disposable scopes to include GUILayout.FlexibleSpace. I extended the VerticalScope class, and added the FlexibleSpace to the constructor and the CloseScope() method, which is called in the disposal. Thing is, the flexible space in the constructor works fine, but the one in the CloseScope() method does not appear to work. Will FlexibleSpace not work in disposal?
public class VertFlexScope : EditorGUILayout.VerticalScope
{
public VertFlexScope()
{
GUILayout.FlexibleSpace();
}
protected override void CloseScope()
{
GUILayout.FlexibleSpace();
EditorGUILayout.EndVertical();
}
}