diff --git a/Source/Editor/CustomEditors/GUI/PropertiesList.cs b/Source/Editor/CustomEditors/GUI/PropertiesList.cs index ef90fc706..3847a8f36 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 EditorsMinWidthRatio = 0.4f; /// /// The splitter size (in pixels). @@ -25,6 +28,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]). @@ -66,6 +70,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 - EditorsMinWidthRatio); + } + private void UpdateSplitRect() { _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; Cursor = CursorType.SizeWE; _cursorChanged = true; + _hasCustomSplitterValue = true; } else if (_mouseOverSplitter) { @@ -195,6 +220,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 4c1061d4a..f26506c74 100644 --- a/Source/Editor/Options/InterfaceOptions.cs +++ b/Source/Editor/Options/InterfaceOptions.cs @@ -228,6 +228,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. ///