Add splitter bar for resizing curve editor inside properties panel

This commit is contained in:
Wojtek Figat
2024-11-30 23:44:23 +01:00
parent 0295e1ca90
commit f0f631a48b
3 changed files with 127 additions and 84 deletions

View File

@@ -2,6 +2,7 @@
using FlaxEditor.GUI; using FlaxEditor.GUI;
using FlaxEngine; using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.CustomEditors.Dedicated namespace FlaxEditor.CustomEditors.Dedicated
{ {
@@ -13,6 +14,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
private bool _isSetting; private bool _isSetting;
private int _firstTimeShow; private int _firstTimeShow;
private BezierCurveEditor<T> _curve; private BezierCurveEditor<T> _curve;
private Splitter _splitter;
/// <inheritdoc /> /// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout) public override void Initialize(LayoutElementsContainer layout)
@@ -22,6 +24,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
_curve.Height = 120.0f; _curve.Height = 120.0f;
_curve.Edited += OnCurveEdited; _curve.Edited += OnCurveEdited;
_firstTimeShow = 4; // For some weird reason it needs several frames of warmup (probably due to sliders smoothing) _firstTimeShow = 4; // For some weird reason it needs several frames of warmup (probably due to sliders smoothing)
_splitter = new Splitter
{
Moved = OnSplitterMoved,
Parent = _curve,
AnchorPreset = AnchorPresets.HorizontalStretchBottom,
Bounds = new Rectangle(0, _curve.Height - Splitter.DefaultHeight, _curve.Width, Splitter.DefaultHeight),
};
} }
private void OnCurveEdited() private void OnCurveEdited()
@@ -34,6 +43,11 @@ namespace FlaxEditor.CustomEditors.Dedicated
_isSetting = false; _isSetting = false;
} }
private void OnSplitterMoved(Float2 location)
{
_curve.Height = Mathf.Clamp(_splitter.PointToParent(location).Y, 50.0f, 1000.0f);
}
/// <inheritdoc /> /// <inheritdoc />
public override void Refresh() public override void Refresh()
{ {
@@ -54,6 +68,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
protected override void Deinitialize() protected override void Deinitialize()
{ {
_curve = null; _curve = null;
_splitter = null;
base.Deinitialize(); base.Deinitialize();
} }
@@ -117,6 +132,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
private bool _isSetting; private bool _isSetting;
private int _firstTimeShow; private int _firstTimeShow;
private LinearCurveEditor<T> _curve; private LinearCurveEditor<T> _curve;
private Splitter _splitter;
/// <inheritdoc /> /// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout) public override void Initialize(LayoutElementsContainer layout)
@@ -126,6 +142,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
_curve.Height = 120.0f; _curve.Height = 120.0f;
_curve.Edited += OnCurveEdited; _curve.Edited += OnCurveEdited;
_firstTimeShow = 4; // For some weird reason it needs several frames of warmup (probably due to sliders smoothing) _firstTimeShow = 4; // For some weird reason it needs several frames of warmup (probably due to sliders smoothing)
_splitter = new Splitter
{
Moved = OnSplitterMoved,
Parent = _curve,
AnchorPreset = AnchorPresets.HorizontalStretchBottom,
Bounds = new Rectangle(0, _curve.Height - Splitter.DefaultHeight, _curve.Width, Splitter.DefaultHeight),
};
} }
private void OnCurveEdited() private void OnCurveEdited()
@@ -138,6 +161,11 @@ namespace FlaxEditor.CustomEditors.Dedicated
_isSetting = false; _isSetting = false;
} }
private void OnSplitterMoved(Float2 location)
{
_curve.Height = Mathf.Clamp(_splitter.PointToParent(location).Y, 50.0f, 1000.0f);
}
/// <inheritdoc /> /// <inheritdoc />
public override void Refresh() public override void Refresh()
{ {
@@ -158,6 +186,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
protected override void Deinitialize() protected override void Deinitialize()
{ {
_curve = null; _curve = null;
_splitter = null;
base.Deinitialize(); base.Deinitialize();
} }

View File

@@ -0,0 +1,86 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.GUI
{
sealed class Splitter : Control
{
private bool _clicked;
public Action<Float2> Moved;
public const float DefaultHeight = 5.0f;
public override void Draw()
{
var style = Style.Current;
if (IsMouseOver || _clicked)
Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _clicked ? style.BackgroundSelected : style.BackgroundHighlighted);
}
public override void OnEndMouseCapture()
{
base.OnEndMouseCapture();
_clicked = false;
}
public override void Defocus()
{
base.Defocus();
_clicked = false;
}
public override void OnMouseEnter(Float2 location)
{
base.OnMouseEnter(location);
Cursor = CursorType.SizeNS;
}
public override void OnMouseLeave()
{
Cursor = CursorType.Default;
base.OnMouseLeave();
}
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
{
_clicked = true;
Focus();
StartMouseCapture();
return true;
}
return base.OnMouseDown(location, button);
}
public override void OnMouseMove(Float2 location)
{
base.OnMouseMove(location);
if (_clicked)
{
Moved(location);
}
}
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left && _clicked)
{
_clicked = false;
EndMouseCapture();
return true;
}
return base.OnMouseUp(location, button);
}
}
}

View File

@@ -19,87 +19,6 @@ namespace FlaxEditor.GUI.Timeline.Tracks
/// <seealso cref="MemberTrack" /> /// <seealso cref="MemberTrack" />
public abstract class CurvePropertyTrackBase : MemberTrack, IKeyframesEditorContext public abstract class CurvePropertyTrackBase : MemberTrack, IKeyframesEditorContext
{ {
private sealed class Splitter : Control
{
private bool _clicked;
internal CurvePropertyTrackBase _track;
public override void Draw()
{
var style = Style.Current;
if (IsMouseOver || _clicked)
Render2D.FillRectangle(new Rectangle(Float2.Zero, Size), _clicked ? style.BackgroundSelected : style.BackgroundHighlighted);
}
public override void OnEndMouseCapture()
{
base.OnEndMouseCapture();
_clicked = false;
}
public override void Defocus()
{
base.Defocus();
_clicked = false;
}
public override void OnMouseEnter(Float2 location)
{
base.OnMouseEnter(location);
Cursor = CursorType.SizeNS;
}
public override void OnMouseLeave()
{
Cursor = CursorType.Default;
base.OnMouseLeave();
}
public override bool OnMouseDown(Float2 location, MouseButton button)
{
if (button == MouseButton.Left)
{
_clicked = true;
Focus();
StartMouseCapture();
return true;
}
return base.OnMouseDown(location, button);
}
public override void OnMouseMove(Float2 location)
{
base.OnMouseMove(location);
if (_clicked)
{
var height = Mathf.Clamp(PointToParent(location).Y, 40.0f, 1000.0f);
if (!Mathf.NearEqual(height, _track._expandedHeight))
{
_track.Height = _track._expandedHeight = height;
_track.Timeline.ArrangeTracks();
}
}
}
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (button == MouseButton.Left && _clicked)
{
_clicked = false;
EndMouseCapture();
return true;
}
return base.OnMouseUp(location, button);
}
}
private byte[] _curveEditingStartData; private byte[] _curveEditingStartData;
private float _expandedHeight = 120.0f; private float _expandedHeight = 120.0f;
private Splitter _splitter; private Splitter _splitter;
@@ -251,12 +170,21 @@ namespace FlaxEditor.GUI.Timeline.Tracks
{ {
_splitter = new Splitter _splitter = new Splitter
{ {
_track = this, Moved = OnSplitterMoved,
Parent = Curve, Parent = Curve,
}; };
} }
var splitterHeight = 5.0f; _splitter.Bounds = new Rectangle(0, Curve.Height - Splitter.DefaultHeight, Curve.Width, Splitter.DefaultHeight);
_splitter.Bounds = new Rectangle(0, Curve.Height - splitterHeight, Curve.Width, splitterHeight); }
}
private void OnSplitterMoved(Float2 location)
{
var height = Mathf.Clamp(PointToParent(location).Y, 40.0f, 1000.0f);
if (!Mathf.NearEqual(height, _expandedHeight))
{
Height = _expandedHeight = height;
Timeline.ArrangeTracks();
} }
} }