From 9192375ddb6d89576c301ad52a905ca4ad67f835 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Tue, 5 Jul 2022 10:36:36 +0200 Subject: [PATCH] Improve properties display (group all parameters from the same group together) --- .../CustomEditors/Editors/GenericEditor.cs | 72 +++++++++++-------- Source/Editor/Surface/VisjectSurfaceWindow.cs | 22 ++---- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index 489c324e5..062316547 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -84,11 +84,6 @@ namespace FlaxEditor.CustomEditors.Editors /// public string DisplayName { get; } - /// - /// Gets a value indicating whether use dedicated group. - /// - public bool UseGroup => Display?.Group != null; - /// /// Gets the overridden custom editor for item editing. /// @@ -230,6 +225,7 @@ namespace FlaxEditor.CustomEditors.Editors } private static HashSet _visibleIfPropertiesListsCache; + private static Dictionary _groups; private VisibleIfCache[] _visibleIfCaches; private bool _isNull; @@ -335,7 +331,7 @@ namespace FlaxEditor.CustomEditors.Editors return ScriptMemberInfo.Null; } - private void GroupPanelCheckIfCanRevert(LayoutElementsContainer layout, ref bool canRevertReference, ref bool canRevertDefault) + private static void GroupPanelCheckIfCanRevert(LayoutElementsContainer layout, ref bool canRevertReference, ref bool canRevertDefault) { if (layout == null || canRevertReference && canRevertDefault) return; @@ -350,7 +346,7 @@ namespace FlaxEditor.CustomEditors.Editors GroupPanelCheckIfCanRevert(child as LayoutElementsContainer, ref canRevertReference, ref canRevertDefault); } - private void OnGroupPanelRevert(LayoutElementsContainer layout, bool toDefault) + private static void OnGroupPanelRevert(LayoutElementsContainer layout, bool toDefault) { if (layout == null) return; @@ -367,7 +363,7 @@ namespace FlaxEditor.CustomEditors.Editors OnGroupPanelRevert(child as LayoutElementsContainer, toDefault); } - private void OnGroupPanelCopy(LayoutElementsContainer layout) + private static void OnGroupPanelCopy(LayoutElementsContainer layout) { if (layout.Editors.Count == 1) { @@ -403,12 +399,12 @@ namespace FlaxEditor.CustomEditors.Editors } } - private bool OnGroupPanelCanCopy(LayoutElementsContainer layout) + private static bool OnGroupPanelCanCopy(LayoutElementsContainer layout) { return layout.Editors.Count != 0 || layout.Children.Any(x => x is LayoutElementsContainer); } - private void OnGroupPanelPaste(LayoutElementsContainer layout) + private static void OnGroupPanelPaste(LayoutElementsContainer layout) { if (layout.Editors.Count == 1) { @@ -452,7 +448,7 @@ namespace FlaxEditor.CustomEditors.Editors } } - private bool OnGroupPanelCanPaste(LayoutElementsContainer layout) + private static bool OnGroupPanelCanPaste(LayoutElementsContainer layout) { if (layout.Editors.Count == 1) { @@ -498,7 +494,7 @@ namespace FlaxEditor.CustomEditors.Editors return false; } - private void OnGroupPanelMouseButtonRightClicked(DropPanel groupPanel, Float2 location) + private static void OnGroupPanelMouseButtonRightClicked(DropPanel groupPanel, Float2 location) { var group = (GroupElement)groupPanel.Tag; bool canRevertReference = false, canRevertDefault = false; @@ -518,6 +514,36 @@ namespace FlaxEditor.CustomEditors.Editors menu.Show(groupPanel, location); } + internal static void OnGroupUsage() + { + if (_groups != null) + _groups.Clear(); + } + + internal static LayoutElementsContainer OnGroup(LayoutElementsContainer layout, EditorDisplayAttribute display) + { + if (display?.Group != null) + { + if (_groups != null && _groups.TryGetValue(display.Group, out var group)) + { + // Reuse group + layout = group; + } + else + { + // Add new group + if (_groups == null) + _groups = new Dictionary(); + group = layout.Group(display.Group); + group.Panel.Tag = group; + group.Panel.MouseButtonRightClicked += OnGroupPanelMouseButtonRightClicked; + _groups.Add(display.Group, group); + layout = group; + } + } + return layout; + } + /// /// Spawns the property for the given item. /// @@ -687,28 +713,13 @@ namespace FlaxEditor.CustomEditors.Editors items.Sort(); // Add items - GroupElement lastGroup = null; + OnGroupUsage(); for (int i = 0; i < items.Count; i++) { var item = items[i]; - // Check if use group - LayoutElementsContainer itemLayout; - if (item.UseGroup) - { - if (lastGroup == null || lastGroup.Panel.HeaderText != item.Display.Group) - { - lastGroup = layout.Group(item.Display.Group); - lastGroup.Panel.Tag = lastGroup; - lastGroup.Panel.MouseButtonRightClicked += OnGroupPanelMouseButtonRightClicked; - } - itemLayout = lastGroup; - } - else - { - lastGroup = null; - itemLayout = layout; - } + // Group + var itemLayout = OnGroup(layout, item.Display); // Space if (item.Space != null) @@ -748,6 +759,7 @@ namespace FlaxEditor.CustomEditors.Editors } while (c != null); } } + OnGroupUsage(); } /// diff --git a/Source/Editor/Surface/VisjectSurfaceWindow.cs b/Source/Editor/Surface/VisjectSurfaceWindow.cs index b7df01cc2..d6b68030d 100644 --- a/Source/Editor/Surface/VisjectSurfaceWindow.cs +++ b/Source/Editor/Surface/VisjectSurfaceWindow.cs @@ -372,8 +372,7 @@ namespace FlaxEditor.Surface return; } var parameters = window.VisjectSurface.Parameters; - GroupElement lastGroup = null; - + CustomEditors.Editors.GenericEditor.OnGroupUsage(); for (int i = 0; i < parameters.Count; i++) { var p = parameters[i]; @@ -385,25 +384,13 @@ namespace FlaxEditor.Surface var attributes = p.Meta.GetAttributes(); if (attributes == null || attributes.Length == 0) attributes = DefaultAttributes; - var itemLayout = layout; var name = p.Name; // Editor Display var editorDisplay = (EditorDisplayAttribute)attributes.FirstOrDefault(x => x is EditorDisplayAttribute); - if (editorDisplay?.Group != null) - { - if (lastGroup == null || lastGroup.Panel.HeaderText != editorDisplay.Group) - { - lastGroup = layout.Group(editorDisplay.Group); - lastGroup.Panel.Open(false); - } - itemLayout = lastGroup; - } - else - { - lastGroup = null; - itemLayout = layout; - } + var itemLayout = CustomEditors.Editors.GenericEditor.OnGroup(layout, editorDisplay); + if (itemLayout is GroupElement groupElement) + groupElement.Panel.Open(false); if (editorDisplay?.Name != null) name = editorDisplay.Name; @@ -442,6 +429,7 @@ namespace FlaxEditor.Surface var property = itemLayout.AddPropertyItem(propertyLabel, tooltipText); property.Object(propertyValue); } + CustomEditors.Editors.GenericEditor.OnGroupUsage(); // Parameters creating var newParameterTypes = window.NewParameterTypes;