Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix layout bugs #93

Merged
merged 3 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Editor.Integrations/Odin/OdinFieldDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ protected override void DrawPropertyLayout(GUIContent label)
}

_propertyTree.Update();

if (_propertyTree.ValidationRequired)
{
_propertyTree.RunValidation();
}
_propertyTree.RunValidationIfRequired();

_labelOverrideContext.Label = label ?? GUIContent.none;

Expand Down
6 changes: 1 addition & 5 deletions Editor.Integrations/Odin/OdinObjectDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ protected override void DrawPropertyLayout(GUIContent label)
}

_propertyTree.Update();

if (_propertyTree.ValidationRequired)
{
_propertyTree.RunValidation();
}
_propertyTree.RunValidationIfRequired();

using (TriGuiHelper.PushEditorTarget(ValueEntry.SmartValue))
{
Expand Down
9 changes: 2 additions & 7 deletions Editor.Samples/TriSamplesWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,15 @@ private void DrawElement()

_currentSerializedObject.UpdateIfRequiredOrScript();
_currentPropertyTree.Update();

if (_currentPropertyTree.ValidationRequired)
{
_currentPropertyTree.RunValidation();
}
_currentPropertyTree.RunValidationIfRequired();

GUILayout.Space(10);
GUILayout.Label("Preview", EditorStyles.boldLabel);

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())
Expand Down
2 changes: 2 additions & 0 deletions Editor/Elements/TriHeaderGroupBaseElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
6 changes: 1 addition & 5 deletions Editor/TriEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public override void OnInspectorGUI()
serializedObject.UpdateIfRequiredOrScript();

_inspector.Update();

if (_inspector.ValidationRequired)
{
_inspector.RunValidation();
}
_inspector.RunValidationIfRequired();

using (TriGuiHelper.PushEditorTarget(target))
{
Expand Down
27 changes: 19 additions & 8 deletions Editor/TriPropertyTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -39,6 +40,16 @@ public virtual bool ApplyChanges()
return false;
}

public void RunValidationIfRequired()
{
if (!ValidationRequired)
{
return;
}

RunValidation();
}

public void RunValidation()
{
ValidationRequired = false;
Expand All @@ -48,7 +59,7 @@ public void RunValidation()
RequestRepaint();
}

public virtual void Draw(float? viewWidth = null)
public virtual void Draw()
{
RepaintRequired = false;

Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Editor/TriPropertyTreeForSerializedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down