From 468babae87c628a838c01808aeb03e6d7dfd9e65 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Sun, 16 Mar 2025 20:32:20 +0100 Subject: [PATCH 1/2] auto resize PropertiesList splitter bar based on longest text --- .../CustomEditors/GUI/PropertiesList.cs | 26 +++++++++++++++++++ Source/Editor/Options/InterfaceOptions.cs | 7 +++++ 2 files changed, 33 insertions(+) diff --git a/Source/Editor/CustomEditors/GUI/PropertiesList.cs b/Source/Editor/CustomEditors/GUI/PropertiesList.cs index 49eef13d2..43b05f483 100644 --- a/Source/Editor/CustomEditors/GUI/PropertiesList.cs +++ b/Source/Editor/CustomEditors/GUI/PropertiesList.cs @@ -14,6 +14,9 @@ namespace FlaxEditor.CustomEditors.GUI public class PropertiesList : PanelWithMargins { // TODO: sync splitter for whole presenter + + private const float splitterPadding = 15; + private const float editorsMinWdithRatio = 0.4f; /// /// The splitter size (in pixels). @@ -32,6 +35,7 @@ namespace FlaxEditor.CustomEditors.GUI private Rectangle _splitterRect; private bool _splitterClicked, _mouseOverSplitter; private bool _cursorChanged; + private bool _hasCustomSplitterValue; /// /// Gets or sets the splitter value (always in range [0; 1]). @@ -71,6 +75,26 @@ namespace FlaxEditor.CustomEditors.GUI 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 - editorsMinWdithRatio); + } + private void UpdateSplitRect() { _splitterRect = new Rectangle(Mathf.Clamp(_splitterValue * Width - SplitterSizeHalf, 0.0f, Width), 0, SplitterSize, Height); @@ -127,6 +151,7 @@ namespace FlaxEditor.CustomEditors.GUI SplitterValue = location.X / Width; Cursor = CursorType.SizeWE; _cursorChanged = true; + _hasCustomSplitterValue = true; } else if (_mouseOverSplitter) { @@ -200,6 +225,7 @@ namespace FlaxEditor.CustomEditors.GUI // Refresh UpdateSplitRect(); PerformLayout(true); + AutoSizeSplitter(); } /// diff --git a/Source/Editor/Options/InterfaceOptions.cs b/Source/Editor/Options/InterfaceOptions.cs index 3b80cd63c..baed5275a 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -232,6 +232,13 @@ namespace FlaxEditor.Options [EditorDisplay("Interface"), EditorOrder(310)] public bool SeparateValueAndUnit { get; set; } + /// + /// Gets or sets the option to auto size the Properties panel splitter based on the longest property name. Editor restart recommended. + /// + [DefaultValue(false)] + [EditorDisplay("Interface"), EditorOrder(311)] + public bool AutoSizePropertiesPanelSplitter { get; set; } + /// /// Gets or sets tree line visibility. /// From 975cc790855be9b62d2f48c6066a9bca32508c7e Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Sun, 16 Mar 2025 22:18:21 +0100 Subject: [PATCH 2/2] code style fixes --- Source/Editor/CustomEditors/GUI/PropertiesList.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/Editor/CustomEditors/GUI/PropertiesList.cs b/Source/Editor/CustomEditors/GUI/PropertiesList.cs index 43b05f483..60bafc215 100644 --- a/Source/Editor/CustomEditors/GUI/PropertiesList.cs +++ b/Source/Editor/CustomEditors/GUI/PropertiesList.cs @@ -15,8 +15,8 @@ namespace FlaxEditor.CustomEditors.GUI { // TODO: sync splitter for whole presenter - private const float splitterPadding = 15; - private const float editorsMinWdithRatio = 0.4f; + private const float SplitterPadding = 15; + private const float EditorsMinWidthRatio = 0.4f; /// /// The splitter size (in pixels). @@ -87,12 +87,12 @@ namespace FlaxEditor.CustomEditors.GUI { Label currentLabel = _element.Labels[i]; Float2 dimensions = font.MeasureText(currentLabel.Text); - float width = dimensions.X + currentLabel.Margin.Left + splitterPadding; + float width = dimensions.X + currentLabel.Margin.Left + SplitterPadding; largestWidth = Mathf.Max(largestWidth, width); } - SplitterValue = Mathf.Clamp(largestWidth / Width, 0, 1 - editorsMinWdithRatio); + SplitterValue = Mathf.Clamp(largestWidth / Width, 0, 1 - EditorsMinWidthRatio); } private void UpdateSplitRect()