Merge branch 'AutoSizePropertiesSplitter' of https://github.com/xxSeys1/FlaxEngine into xxSeys1-AutoSizePropertiesSplitter

This commit is contained in:
Wojtek Figat
2025-08-24 13:59:16 +02:00
2 changed files with 33 additions and 0 deletions

View File

@@ -14,6 +14,9 @@ namespace FlaxEditor.CustomEditors.GUI
public class PropertiesList : PanelWithMargins public class PropertiesList : PanelWithMargins
{ {
// TODO: sync splitter for whole presenter // TODO: sync splitter for whole presenter
private const float SplitterPadding = 15;
private const float EditorsMinWidthRatio = 0.4f;
/// <summary> /// <summary>
/// The splitter size (in pixels). /// The splitter size (in pixels).
@@ -25,6 +28,7 @@ namespace FlaxEditor.CustomEditors.GUI
private Rectangle _splitterRect; private Rectangle _splitterRect;
private bool _splitterClicked, _mouseOverSplitter; private bool _splitterClicked, _mouseOverSplitter;
private bool _cursorChanged; private bool _cursorChanged;
private bool _hasCustomSplitterValue;
/// <summary> /// <summary>
/// Gets or sets the splitter value (always in range [0; 1]). /// Gets or sets the splitter value (always in range [0; 1]).
@@ -66,6 +70,26 @@ namespace FlaxEditor.CustomEditors.GUI
UpdateSplitRect(); UpdateSplitRect();
} }
private void AutoSizeSplitter()
{
if (_hasCustomSplitterValue || !Editor.Instance.Options.Options.Interface.AutoSizePropertiesPanelSplitter)
return;
Font font = Style.Current.FontMedium;
float largestWidth = 0f;
for (int i = 0; i < _element.Labels.Count; i++)
{
Label currentLabel = _element.Labels[i];
Float2 dimensions = font.MeasureText(currentLabel.Text);
float width = dimensions.X + currentLabel.Margin.Left + SplitterPadding;
largestWidth = Mathf.Max(largestWidth, width);
}
SplitterValue = Mathf.Clamp(largestWidth / Width, 0, 1 - EditorsMinWidthRatio);
}
private void UpdateSplitRect() private void UpdateSplitRect()
{ {
_splitterRect = new Rectangle(Mathf.Clamp(_splitterValue * Width - SplitterSize * 0.5f, 0.0f, Width), 0, SplitterSize, Height); _splitterRect = new Rectangle(Mathf.Clamp(_splitterValue * Width - SplitterSize * 0.5f, 0.0f, Width), 0, SplitterSize, Height);
@@ -122,6 +146,7 @@ namespace FlaxEditor.CustomEditors.GUI
SplitterValue = location.X / Width; SplitterValue = location.X / Width;
Cursor = CursorType.SizeWE; Cursor = CursorType.SizeWE;
_cursorChanged = true; _cursorChanged = true;
_hasCustomSplitterValue = true;
} }
else if (_mouseOverSplitter) else if (_mouseOverSplitter)
{ {
@@ -195,6 +220,7 @@ namespace FlaxEditor.CustomEditors.GUI
// Refresh // Refresh
UpdateSplitRect(); UpdateSplitRect();
PerformLayout(true); PerformLayout(true);
AutoSizeSplitter();
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@@ -228,6 +228,13 @@ namespace FlaxEditor.Options
[EditorDisplay("Interface"), EditorOrder(310)] [EditorDisplay("Interface"), EditorOrder(310)]
public bool SeparateValueAndUnit { get; set; } public bool SeparateValueAndUnit { get; set; }
/// <summary>
/// Gets or sets the option to auto size the Properties panel splitter based on the longest property name. Editor restart recommended.
/// </summary>
[DefaultValue(false)]
[EditorDisplay("Interface"), EditorOrder(311)]
public bool AutoSizePropertiesPanelSplitter { get; set; }
/// <summary> /// <summary>
/// Gets or sets tree line visibility. /// Gets or sets tree line visibility.
/// </summary> /// </summary>