Fix GUI indents

This commit is contained in:
VladV 2022-08-28 10:42:45 +03:00
parent a2f7887208
commit 858da9e174
12 changed files with 41 additions and 52 deletions

View File

@ -57,7 +57,6 @@ namespace TriInspector.Drawers
name = property.RawName;
}
position = EditorGUI.IndentedRect(position);
if (GUI.Button(position, name))
{
InvokeButton(property, Array.Empty<object>());

View File

@ -11,9 +11,9 @@ namespace TriInspector.Drawers
{
public override void OnGUI(Rect position, TriProperty property, TriElement next)
{
using (TriGuiHelper.PushIndentLevel(Attribute.Indent))
using (var indentedRectScope = TriGuiHelper.PushIndentedRect(position, Attribute.Indent))
{
next.OnGUI(position);
next.OnGUI(indentedRectScope.IndentedRect);
}
}
}

View File

@ -58,10 +58,7 @@ namespace TriInspector.Drawers
xMin = prefixRect.xMax,
};
using (TriGuiHelper.PushIndentLevel())
{
TriEditorGUI.Foldout(prefixRect, _property);
}
TriEditorGUI.Foldout(prefixRect, _property);
EditorGUI.BeginChangeCheck();

View File

@ -94,8 +94,6 @@ namespace TriInspector.Drawers
public override void OnGUI(Rect position)
{
position = EditorGUI.IndentedRect(position);
var headerRect = new Rect(position)
{
height = ListGui.headerHeight,
@ -325,7 +323,6 @@ namespace TriInspector.Drawers
var cellElement = rowElement.Elements[visibleColumnIndex - 1].Key;
cellRect.height = cellElement.GetHeight(cellRect.width);
using (TriGuiHelper.PushIndentLevel(-EditorGUI.indentLevel))
using (TriGuiHelper.PushLabelWidth(EditorGUIUtility.labelWidth / rowElement.ChildrenCount))
using (TriPropertyOverrideContext.BeginOverride(_propertyOverrideContext))
{

View File

@ -87,13 +87,7 @@ namespace TriInspector.Elements
if (_editor != null && shouldDrawEditor)
{
Rect indentedEditorPosition;
using (TriGuiHelper.PushIndentLevel())
{
indentedEditorPosition = EditorGUI.IndentedRect(_editorPosition);
}
GUILayout.BeginArea(indentedEditorPosition);
GUILayout.BeginArea(_editorPosition);
GUILayout.BeginVertical();
_editor.OnInspectorGUI();
GUILayout.EndVertical();

View File

@ -65,9 +65,9 @@ namespace TriInspector.Elements
return;
}
using (TriGuiHelper.PushIndentLevel())
using (var indentedRectScope = TriGuiHelper.PushIndentedRect(contentRect, 1))
{
base.OnGUI(contentRect);
base.OnGUI(indentedRectScope.IndentedRect);
}
}

View File

@ -8,7 +8,7 @@ namespace TriInspector.Elements
{
private const float InsetTop = 4;
private const float InsetBottom = 4;
private const float InsetLeft = 4;
private const float InsetLeft = 18;
private const float InsetRight = 4;
protected virtual float GetHeaderHeight(float width)

View File

@ -28,8 +28,6 @@ namespace TriInspector.Elements
public override void OnGUI(Rect position)
{
position = EditorGUI.IndentedRect(position);
using (TriGuiHelper.PushColor(_color))
{
GUI.Label(position, string.Empty, Styles.InfoBoxBg);

View File

@ -103,8 +103,6 @@ namespace TriInspector.Elements
public override void OnGUI(Rect position)
{
position = EditorGUI.IndentedRect(position);
if (!_property.IsExpanded)
{
ReorderableListProxy.DoListHeader(_reorderableListGui, new Rect(position)
@ -277,27 +275,24 @@ namespace TriInspector.Elements
private void DrawHeaderCallback(Rect rect)
{
using (TriGuiHelper.PushIndentLevel(-EditorGUI.indentLevel))
var labelRect = new Rect(rect);
var arraySizeRect = new Rect(rect)
{
var labelRect = new Rect(rect);
var arraySizeRect = new Rect(rect)
{
xMin = rect.xMax - 100,
};
xMin = rect.xMax - 100,
};
if (_alwaysExpanded)
{
EditorGUI.LabelField(labelRect, _property.DisplayNameContent);
}
else
{
labelRect.x += 10;
TriEditorGUI.Foldout(labelRect, _property);
}
var label = _reorderableListGui.count == 0 ? "Empty" : $"{_reorderableListGui.count} items";
GUI.Label(arraySizeRect, label, Styles.ItemsCount);
if (_alwaysExpanded)
{
EditorGUI.LabelField(labelRect, _property.DisplayNameContent);
}
else
{
labelRect.x += 10;
TriEditorGUI.Foldout(labelRect, _property);
}
var label = _reorderableListGui.count == 0 ? "Empty" : $"{_reorderableListGui.count} items";
GUI.Label(arraySizeRect, label, Styles.ItemsCount);
}
private void DrawElementCallback(Rect rect, int index, bool isActive, bool isFocused)

View File

@ -112,10 +112,10 @@ namespace TriInspector.Elements
if (_property.IsExpanded)
{
using (TriGuiHelper.PushIndentLevel())
using (var indentedRectScope = TriGuiHelper.PushIndentedRect(contentRect, 1))
using (TriGuiHelper.PushLabelWidth(_props.labelWidth))
{
base.OnGUI(contentRect);
base.OnGUI(indentedRectScope.IndentedRect);
}
}
}

View File

@ -71,7 +71,13 @@ namespace TriInspector
rect.xMin += 3;
}
rect = EditorGUI.IndentedRect(rect);
var oldIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
_rootPropertyElement.OnGUI(rect);
EditorGUI.indentLevel = oldIndent;
}
public void EnumerateValidationResults(Action<TriProperty, TriValidationResult> call)

View File

@ -38,9 +38,9 @@ namespace TriInspector.Utilities
return new LabelWidthScope(labelWidth);
}
public static IndentLevelScope PushIndentLevel(int indent = 1)
public static IndentedRectScope PushIndentedRect(Rect source, int indentLevel)
{
return new IndentLevelScope(indent);
return new IndentedRectScope(source, indentLevel);
}
public static GuiColorScope PushColor(Color color)
@ -81,20 +81,23 @@ namespace TriInspector.Utilities
}
}
public readonly struct IndentLevelScope : IDisposable
public readonly struct IndentedRectScope : IDisposable
{
private readonly int _oldIndentLevel;
private readonly float _indent;
public IndentLevelScope(int indentLevel)
public Rect IndentedRect { get; }
public IndentedRectScope(Rect source, int indentLevel)
{
_oldIndentLevel = EditorGUI.indentLevel;
_indent = indentLevel * 15;
EditorGUI.indentLevel += indentLevel;
IndentedRect = new Rect(source.x + _indent, source.y, source.width - _indent, source.height);
EditorGUIUtility.labelWidth -= _indent;
}
public void Dispose()
{
EditorGUI.indentLevel = _oldIndentLevel;
EditorGUIUtility.labelWidth += _indent;
}
}