Skip to content

Commit db3d602

Browse files
committed
More stable size calculations
1 parent a416601 commit db3d602

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Editor.Samples/TriSamplesWindow.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ private void DrawElement()
106106
using (TriGuiHelper.PushEditorTarget(_current))
107107
using (new GUILayout.VerticalScope(SampleWindowStyles.BoxWithPadding))
108108
{
109-
var viewWidth = GUILayoutUtility.GetRect(0, 10000, 0, 0).width;
110-
_currentPropertyTree.Draw(viewWidth);
109+
_currentPropertyTree.Draw();
111110
}
112111

113112
if (_currentSerializedObject.ApplyModifiedProperties())

Editor/TriPropertyTree.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace TriInspector
88
public abstract class TriPropertyTree
99
{
1010
private TriPropertyElement _rootPropertyElement;
11+
private Rect _cachedOuterRect = new Rect(0, 0, 0, 0);
1112

1213
public TriPropertyDefinition RootPropertyDefinition { get; protected set; }
1314
public TriProperty RootProperty { get; protected set; }
@@ -48,7 +49,7 @@ public void RunValidation()
4849
RequestRepaint();
4950
}
5051

51-
public virtual void Draw(float? viewWidth = null)
52+
public virtual void Draw()
5253
{
5354
RepaintRequired = false;
5455

@@ -62,19 +63,19 @@ public virtual void Draw(float? viewWidth = null)
6263
}
6364

6465
_rootPropertyElement.Update();
65-
var width = viewWidth ?? GUILayoutUtility.GetRect(0, 9999, 0, 0).width;
66-
var height = _rootPropertyElement.GetHeight(width);
67-
var rect = GUILayoutUtility.GetRect(width, height);
6866

69-
if (viewWidth == null)
70-
{
71-
rect.xMin += 3;
72-
}
67+
var rectOuter = GUILayoutUtility.GetRect(0, 9999, 0, 0);
68+
_cachedOuterRect = Event.current.type == EventType.Layout ? _cachedOuterRect : rectOuter;
7369

70+
var rect = new Rect(_cachedOuterRect);
7471
rect = EditorGUI.IndentedRect(rect);
72+
rect.height = _rootPropertyElement.GetHeight(rect.width);
73+
7574
var oldIndent = EditorGUI.indentLevel;
7675
EditorGUI.indentLevel = 0;
7776

77+
GUILayoutUtility.GetRect(_cachedOuterRect.width, rect.height);
78+
7879
_rootPropertyElement.OnGUI(rect);
7980

8081
EditorGUI.indentLevel = oldIndent;

Editor/TriPropertyTreeForSerializedObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public override void Update(bool forceUpdate = false)
5656
base.Update(forceUpdate);
5757
}
5858

59-
public override void Draw(float? viewWidth = null)
59+
public override void Draw()
6060
{
6161
DrawMonoScriptProperty();
6262

63-
base.Draw(viewWidth);
63+
base.Draw();
6464
}
6565

6666
public override bool ApplyChanges()

0 commit comments

Comments
 (0)