diff --git a/Editor.Integrations/Odin/OdinFieldDrawer.cs b/Editor.Integrations/Odin/OdinFieldDrawer.cs index c1b5bdcf..09e925d8 100644 --- a/Editor.Integrations/Odin/OdinFieldDrawer.cs +++ b/Editor.Integrations/Odin/OdinFieldDrawer.cs @@ -66,11 +66,7 @@ protected override void DrawPropertyLayout(GUIContent label) } _propertyTree.Update(); - - if (_propertyTree.ValidationRequired) - { - _propertyTree.RunValidation(); - } + _propertyTree.RunValidationIfRequired(); _labelOverrideContext.Label = label ?? GUIContent.none; diff --git a/Editor.Integrations/Odin/OdinObjectDrawer.cs b/Editor.Integrations/Odin/OdinObjectDrawer.cs index 22b9df79..9c6a207c 100644 --- a/Editor.Integrations/Odin/OdinObjectDrawer.cs +++ b/Editor.Integrations/Odin/OdinObjectDrawer.cs @@ -65,11 +65,7 @@ protected override void DrawPropertyLayout(GUIContent label) } _propertyTree.Update(); - - if (_propertyTree.ValidationRequired) - { - _propertyTree.RunValidation(); - } + _propertyTree.RunValidationIfRequired(); using (TriGuiHelper.PushEditorTarget(ValueEntry.SmartValue)) { diff --git a/Editor.Samples/TriSamplesWindow.cs b/Editor.Samples/TriSamplesWindow.cs index 310e6d69..f8df9862 100644 --- a/Editor.Samples/TriSamplesWindow.cs +++ b/Editor.Samples/TriSamplesWindow.cs @@ -94,11 +94,7 @@ private void DrawElement() _currentSerializedObject.UpdateIfRequiredOrScript(); _currentPropertyTree.Update(); - - if (_currentPropertyTree.ValidationRequired) - { - _currentPropertyTree.RunValidation(); - } + _currentPropertyTree.RunValidationIfRequired(); GUILayout.Space(10); GUILayout.Label("Preview", EditorStyles.boldLabel); @@ -106,8 +102,7 @@ private void DrawElement() using (TriGuiHelper.PushEditorTarget(_current)) using (new GUILayout.VerticalScope(SampleWindowStyles.BoxWithPadding)) { - var viewWidth = GUILayoutUtility.GetRect(0, 10000, 0, 0).width; - _currentPropertyTree.Draw(viewWidth); + _currentPropertyTree.Draw(); } if (_currentSerializedObject.ApplyModifiedProperties()) diff --git a/Editor/Elements/TriHeaderGroupBaseElement.cs b/Editor/Elements/TriHeaderGroupBaseElement.cs index a582c161..cbff466b 100644 --- a/Editor/Elements/TriHeaderGroupBaseElement.cs +++ b/Editor/Elements/TriHeaderGroupBaseElement.cs @@ -52,6 +52,8 @@ public sealed override void OnGUI(Rect position) { xMin = contentBgRect.xMin + InsetLeft, xMax = contentBgRect.xMax - InsetRight, + yMin = contentBgRect.yMin + InsetTop, + yMax = contentBgRect.yMax - InsetBottom, height = contentHeight, }; diff --git a/Editor/TriEditor.cs b/Editor/TriEditor.cs index fb615f75..4420144f 100644 --- a/Editor/TriEditor.cs +++ b/Editor/TriEditor.cs @@ -53,11 +53,7 @@ public override void OnInspectorGUI() serializedObject.UpdateIfRequiredOrScript(); _inspector.Update(); - - if (_inspector.ValidationRequired) - { - _inspector.RunValidation(); - } + _inspector.RunValidationIfRequired(); using (TriGuiHelper.PushEditorTarget(target)) { diff --git a/Editor/TriPropertyTree.cs b/Editor/TriPropertyTree.cs index 1f6c46eb..1fc0d83f 100644 --- a/Editor/TriPropertyTree.cs +++ b/Editor/TriPropertyTree.cs @@ -8,6 +8,7 @@ namespace TriInspector public abstract class TriPropertyTree { private TriPropertyElement _rootPropertyElement; + private Rect _cachedOuterRect = new Rect(0, 0, 0, 0); public TriPropertyDefinition RootPropertyDefinition { get; protected set; } public TriProperty RootProperty { get; protected set; } @@ -39,6 +40,16 @@ public virtual bool ApplyChanges() return false; } + public void RunValidationIfRequired() + { + if (!ValidationRequired) + { + return; + } + + RunValidation(); + } + public void RunValidation() { ValidationRequired = false; @@ -48,7 +59,7 @@ public void RunValidation() RequestRepaint(); } - public virtual void Draw(float? viewWidth = null) + public virtual void Draw() { RepaintRequired = false; @@ -62,19 +73,19 @@ public virtual void Draw(float? viewWidth = null) } _rootPropertyElement.Update(); - var width = viewWidth ?? GUILayoutUtility.GetRect(0, 9999, 0, 0).width; - var height = _rootPropertyElement.GetHeight(width); - var rect = GUILayoutUtility.GetRect(width, height); - if (viewWidth == null) - { - rect.xMin += 3; - } + var rectOuter = GUILayoutUtility.GetRect(0, 9999, 0, 0); + _cachedOuterRect = Event.current.type == EventType.Layout ? _cachedOuterRect : rectOuter; + var rect = new Rect(_cachedOuterRect); rect = EditorGUI.IndentedRect(rect); + rect.height = _rootPropertyElement.GetHeight(rect.width); + var oldIndent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; + GUILayoutUtility.GetRect(_cachedOuterRect.width, rect.height); + _rootPropertyElement.OnGUI(rect); EditorGUI.indentLevel = oldIndent; diff --git a/Editor/TriPropertyTreeForSerializedObject.cs b/Editor/TriPropertyTreeForSerializedObject.cs index f62a56fe..f31fbf6d 100644 --- a/Editor/TriPropertyTreeForSerializedObject.cs +++ b/Editor/TriPropertyTreeForSerializedObject.cs @@ -56,11 +56,11 @@ public override void Update(bool forceUpdate = false) base.Update(forceUpdate); } - public override void Draw(float? viewWidth = null) + public override void Draw() { DrawMonoScriptProperty(); - base.Draw(viewWidth); + base.Draw(); } public override bool ApplyChanges()