From 0c5b8f4480f55bf4fdd21c8e6da9620571c3ff43 Mon Sep 17 00:00:00 2001 From: VladV Date: Sat, 6 Apr 2024 13:11:25 +0300 Subject: [PATCH] Fix InlineEditor preview layout --- Editor.Extras/Drawers/InlineEditorDrawer.cs | 1 - Editor/Elements/InlineEditorElement.cs | 14 ++++---------- Runtime/Attributes/InlineEditorAttribute.cs | 1 - 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/Editor.Extras/Drawers/InlineEditorDrawer.cs b/Editor.Extras/Drawers/InlineEditorDrawer.cs index 170fce8..b98ccc9 100644 --- a/Editor.Extras/Drawers/InlineEditorDrawer.cs +++ b/Editor.Extras/Drawers/InlineEditorDrawer.cs @@ -34,7 +34,6 @@ public override TriElement CreateElement(TriProperty property, TriElement next) { mode = Attribute.Mode, previewHeight = Attribute.PreviewHeight, - previewWidth = Attribute.PreviewWidth, })); return element; } diff --git a/Editor/Elements/InlineEditorElement.cs b/Editor/Elements/InlineEditorElement.cs index c8fea15..3ad1de9 100644 --- a/Editor/Elements/InlineEditorElement.cs +++ b/Editor/Elements/InlineEditorElement.cs @@ -16,7 +16,6 @@ public class InlineEditorElement : TriElement public struct Props { public InlineEditorModes mode; - public float previewWidth; public float previewHeight; public bool DrawGUI => (mode & InlineEditorModes.GUIOnly) != 0; @@ -95,7 +94,7 @@ public override void OnGUI(Rect position) if (_editor != null && shouldDrawEditor) { GUILayout.BeginArea(_editorPosition); - GUILayout.BeginHorizontal(); + GUILayout.BeginVertical(); if (_props.DrawHeader || _props.DrawGUI) { @@ -122,13 +121,8 @@ public override void OnGUI(Rect position) { GUILayout.BeginVertical(); - var horizontal = _props.DrawHeader || _props.DrawGUI; - - var previewOpts = horizontal - ? new[] {GUILayout.Width(_props.previewWidth), GUILayout.ExpandHeight(true),} - : new[] {GUILayout.ExpandWidth(true), GUILayout.Height(_props.previewHeight),}; - - var previewRect = GUILayoutUtility.GetRect(GUIContent.none, GUIStyle.none, previewOpts); + var previewOpts = new[] {GUILayout.ExpandWidth(true), GUILayout.Height(_props.previewHeight),}; + var previewRect = EditorGUILayout.GetControlRect(false, _props.previewHeight, previewOpts); previewRect.width = Mathf.Max(previewRect.width, 10); previewRect.height = Mathf.Max(previewRect.height, 10); @@ -143,7 +137,7 @@ public override void OnGUI(Rect position) GUILayout.EndVertical(); } - GUILayout.EndHorizontal(); + GUILayout.EndVertical(); lastEditorRect = GUILayoutUtility.GetLastRect(); GUILayout.EndArea(); } diff --git a/Runtime/Attributes/InlineEditorAttribute.cs b/Runtime/Attributes/InlineEditorAttribute.cs index f0dbda0..5109d90 100644 --- a/Runtime/Attributes/InlineEditorAttribute.cs +++ b/Runtime/Attributes/InlineEditorAttribute.cs @@ -10,7 +10,6 @@ public class InlineEditorAttribute : Attribute { public InlineEditorModes Mode { get; set; } = InlineEditorModes.GUIOnly; - public float PreviewWidth { get; set; } = 100; public float PreviewHeight { get; set; } = 50; public InlineEditorAttribute()