More stable size calculations

This commit is contained in:
VladV 2023-03-22 11:38:33 +04:00
parent a416601510
commit db3d60270a
3 changed files with 12 additions and 12 deletions

View File

@ -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())

View File

@ -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;

View File

@ -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()