From db3d60270aa185d7f427042ec504d577119e7dab Mon Sep 17 00:00:00 2001 From: VladV Date: Wed, 22 Mar 2023 11:38:33 +0400 Subject: [PATCH] More stable size calculations --- Editor.Samples/TriSamplesWindow.cs | 3 +-- Editor/TriPropertyTree.cs | 17 +++++++++-------- Editor/TriPropertyTreeForSerializedObject.cs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Editor.Samples/TriSamplesWindow.cs b/Editor.Samples/TriSamplesWindow.cs index 310e6d6..8afff63 100644 --- a/Editor.Samples/TriSamplesWindow.cs +++ b/Editor.Samples/TriSamplesWindow.cs @@ -106,8 +106,7 @@ namespace TriInspector.Editor.Samples 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/TriPropertyTree.cs b/Editor/TriPropertyTree.cs index 1f6c46e..76d18e9 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; } @@ -48,7 +49,7 @@ namespace TriInspector RequestRepaint(); } - public virtual void Draw(float? viewWidth = null) + public virtual void Draw() { RepaintRequired = false; @@ -62,19 +63,19 @@ namespace TriInspector } _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 f62a56f..f31fbf6 100644 --- a/Editor/TriPropertyTreeForSerializedObject.cs +++ b/Editor/TriPropertyTreeForSerializedObject.cs @@ -56,11 +56,11 @@ namespace TriInspector base.Update(forceUpdate); } - public override void Draw(float? viewWidth = null) + public override void Draw() { DrawMonoScriptProperty(); - base.Draw(viewWidth); + base.Draw(); } public override bool ApplyChanges()