mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Fix GUI indents
This commit is contained in:
parent
a2f7887208
commit
858da9e174
@ -57,7 +57,6 @@ namespace TriInspector.Drawers
|
||||
name = property.RawName;
|
||||
}
|
||||
|
||||
position = EditorGUI.IndentedRect(position);
|
||||
if (GUI.Button(position, name))
|
||||
{
|
||||
InvokeButton(property, Array.Empty<object>());
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,10 +58,7 @@ namespace TriInspector.Drawers
|
||||
xMin = prefixRect.xMax,
|
||||
};
|
||||
|
||||
using (TriGuiHelper.PushIndentLevel())
|
||||
{
|
||||
TriEditorGUI.Foldout(prefixRect, _property);
|
||||
}
|
||||
TriEditorGUI.Foldout(prefixRect, _property);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
|
@ -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))
|
||||
{
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user