So I have an issue with EditorGUILayout.BeginHorizontal and fields within it.
No matter what I use the labelfields within a horizontal field will space themselves out across a horizontal area rather than snap right next to each other. You can resize the window and see the fields actively move to add/remove the space on their own to fill out the space equally.
I’ve tried using ExpandWidth and labelWidth but nothing changes with their usage.
This is my code:
private GUIStyle AreaStyleNoMargin {
get {
GUIStyle s = new GUIStyle(EditorStyles.textArea) {
margin = new RectOffset(0, 0, 0, 0),
};
return s;
}
}
private GUIStyle AreaStyleNoPadding {
get {
GUIStyle s = new GUIStyle(EditorStyles.textArea) {
padding = new RectOffset(0, 0, 0, 0)
};
return s;
}
}
private GUIStyle AreaStyleNoMarginNoPadding {
get {
GUIStyle s = new GUIStyle(EditorStyles.textArea) {
margin = new RectOffset(0, 0, 0, 0),
padding = new RectOffset(0, 0, 0, 0),
};
return s;
}
}
//....
private void DrawDatabaseEntries() {
CheckInit();
EditorGUILayout.BeginVertical();
{
EditorGUILayout.BeginHorizontal();
{
Rect DBList = EditorGUILayout.BeginVertical(AreaStyleNoPadding, GUILayout.MaxWidth(((position.width / 4) * 3) + 30), GUILayout.MaxHeight((position.height / 4) * 3), GUILayout.MinHeight((position.height / 4) * 3));
{
dbEntriesScroll = GUILayout.BeginScrollView(dbEntriesScroll);
{
GUILayout.Box("", EditorStyles.toolbar, GUILayout.ExpandWidth(true));
GUILayout.Space((EditorGUIUtility.singleLineHeight * -1f) - 2.5f);
//Sorter Tabs
GUILayout.BeginHorizontal();
{
if (GUILayout.Button("ID", TabStyleNoMargin)) {
//DBSort = ManagerDBSort.LoadOrder;
//SortEditorDB();
}
if (GUILayout.Button("Name", TabStyleNoMargin)) {
//DBSort = ManagerDBSort.Name;
//SortEditorDB();
}
}
GUILayout.EndHorizontal();
if (selectedDatabase != null) {
foreach (DatabaseEntry dbE in selectedDatabase.entries) {
EditorGUILayout.BeginHorizontal(AreaStyleNoMarginNoPadding);
EditorGUIUtility.labelWidth = 1;
EditorGUILayout.LabelField(dbE.ID, AreaStyleNoMargin, GUILayout.MaxWidth(60), GUILayout.MinWidth(60), GUILayout.MinHeight(EditorGUIUtility.singleLineHeight + 2), GUILayout.ExpandWidth(false));
EditorGUILayout.LabelField(dbE.Name, AreaStyleNoMargin, GUILayout.MaxWidth(60), GUILayout.MinWidth(60), GUILayout.MinHeight(EditorGUIUtility.singleLineHeight + 2), GUILayout.ExpandWidth(false));
EditorGUIUtility.labelWidth = 0;
EditorGUILayout.EndHorizontal();
}
}
//Draw Lines
Handles.BeginGUI();
Handles.color = Color.gray;
for (int i = 0; i < 7; i++) {
Handles.DrawLine(new Vector2(DBList.position.x + (100 * (i + 1)) - 2, DBList.position.y - 20), new Vector2(DBList.position.x + (100 * (i + 1)) - 2, DBList.position.y + DBList.size.y));
}
Handles.EndGUI();
}
GUILayout.EndScrollView();
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}