Skip to content

Commit

Permalink
Fix InlineEditor preview layout
Browse files Browse the repository at this point in the history
  • Loading branch information
vanifatovvlad committed Apr 6, 2024
1 parent 19b6729 commit 0c5b8f4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
1 change: 0 additions & 1 deletion Editor.Extras/Drawers/InlineEditorDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public override TriElement CreateElement(TriProperty property, TriElement next)
{
mode = Attribute.Mode,
previewHeight = Attribute.PreviewHeight,
previewWidth = Attribute.PreviewWidth,
}));
return element;
}
Expand Down
14 changes: 4 additions & 10 deletions Editor/Elements/InlineEditorElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -143,7 +137,7 @@ public override void OnGUI(Rect position)
GUILayout.EndVertical();
}

GUILayout.EndHorizontal();
GUILayout.EndVertical();
lastEditorRect = GUILayoutUtility.GetLastRect();
GUILayout.EndArea();
}
Expand Down
1 change: 0 additions & 1 deletion Runtime/Attributes/InlineEditorAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0c5b8f4

Please sign in to comment.