From 21be245c5c5563067acd428456a28df60c350765 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 3 Mar 2023 18:43:37 +0100 Subject: [PATCH] Add collapsing to big option groups. --- OtterGui | 2 +- Penumbra/UI/ConfigWindow.ModPanel.Settings.cs | 104 +++++++++++++----- 2 files changed, 78 insertions(+), 28 deletions(-) diff --git a/OtterGui b/OtterGui index 9e98cb97..95a26e94 160000 --- a/OtterGui +++ b/OtterGui @@ -1 +1 @@ -Subproject commit 9e98cb9722bed3129134c7bc2fbe51268b2d6acd +Subproject commit 95a26e944d550a3e77150667af00c23ef307b672 diff --git a/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs b/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs index 9d482c35..10cac9ba 100644 --- a/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs +++ b/Penumbra/UI/ConfigWindow.ModPanel.Settings.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Numerics; using Dalamud.Interface; @@ -231,27 +232,71 @@ public partial class ConfigWindow using var id = ImRaii.PushId( groupIdx ); var selectedOption = _emptySetting ? ( int )group.DefaultSettings : ( int )_settings.Settings[ groupIdx ]; Widget.BeginFramedGroup( group.Name, group.Description ); - for( var idx = 0; idx < group.Count; ++idx ) + + void DrawOptions() { - id.Push( idx ); - var option = group[ idx ]; - if( ImGui.RadioButton( option.Name, selectedOption == idx ) ) + for( var idx = 0; idx < group.Count; ++idx ) { - Penumbra.CollectionManager.Current.SetModSetting( _mod.Index, groupIdx, ( uint )idx ); - } + using var i = ImRaii.PushId( idx ); + var option = group[ idx ]; + if( ImGui.RadioButton( option.Name, selectedOption == idx ) ) + { + Penumbra.CollectionManager.Current.SetModSetting( _mod.Index, groupIdx, ( uint )idx ); + } - if( option.Description.Length > 0 ) - { - ImGui.SameLine(); - ImGuiComponents.HelpMarker( option.Description ); + if( option.Description.Length > 0 ) + { + ImGui.SameLine(); + ImGuiComponents.HelpMarker( option.Description ); + } } - - id.Pop( idx ); } + DrawCollapseHandling( group, DrawOptions ); + Widget.EndFramedGroup(); } + private static void DrawCollapseHandling( IModGroup group, Action draw ) + { + if( group.Count <= 5 ) + { + draw(); + } + else + { + var collapseId = ImGui.GetID( "Collapse" ); + var shown = ImGui.GetStateStorage().GetBool( collapseId, true ); + if( shown ) + { + var pos = ImGui.GetCursorPos(); + ImGui.Dummy( new Vector2( ImGui.GetFrameHeight() ) ); + using( var _ = ImRaii.Group() ) + { + draw(); + } + + var width = ImGui.GetItemRectSize().X; + var endPos = ImGui.GetCursorPos(); + ImGui.SetCursorPos( pos ); + if( ImGui.Button( $"Hide {group.Count} Options", new Vector2( width, 0 ) ) ) + { + ImGui.GetStateStorage().SetBool( collapseId, !shown ); + } + + ImGui.SetCursorPos( endPos ); + } + else + { + var max = group.Max( o => ImGui.CalcTextSize( o.Name ).X ) + ImGui.GetStyle().ItemInnerSpacing.X + ImGui.GetFrameHeight() + ImGui.GetStyle().FramePadding.X; + if( ImGui.Button( $"Show {group.Count} Options", new Vector2( max, 0 ) ) ) + { + ImGui.GetStateStorage().SetBool( collapseId, !shown ); + } + } + } + } + // Draw a multi group selector as a bordered set of checkboxes. // If a description is provided, add a help marker in the title. private void DrawMultiGroup( IModGroup group, int groupIdx ) @@ -259,27 +304,32 @@ public partial class ConfigWindow using var id = ImRaii.PushId( groupIdx ); var flags = _emptySetting ? group.DefaultSettings : _settings.Settings[ groupIdx ]; Widget.BeginFramedGroup( group.Name, group.Description ); - for( var idx = 0; idx < group.Count; ++idx ) + + void DrawOptions() { - var option = group[ idx ]; - id.Push( idx ); - var flag = 1u << idx; - var setting = ( flags & flag ) != 0; - if( ImGui.Checkbox( option.Name, ref setting ) ) + for( var idx = 0; idx < group.Count; ++idx ) { - flags = setting ? flags | flag : flags & ~flag; - Penumbra.CollectionManager.Current.SetModSetting( _mod.Index, groupIdx, flags ); - } + using var i = ImRaii.PushId( idx ); + var option = group[ idx ]; + var flag = 1u << idx; + var setting = ( flags & flag ) != 0; - if( option.Description.Length > 0 ) - { - ImGui.SameLine(); - ImGuiComponents.HelpMarker( option.Description ); - } + if( ImGui.Checkbox( option.Name, ref setting ) ) + { + flags = setting ? flags | flag : flags & ~flag; + Penumbra.CollectionManager.Current.SetModSetting( _mod.Index, groupIdx, flags ); + } - id.Pop(); + if( option.Description.Length > 0 ) + { + ImGui.SameLine(); + ImGuiComponents.HelpMarker( option.Description ); + } + } } + DrawCollapseHandling( group, DrawOptions ); + Widget.EndFramedGroup(); var label = $"##multi{groupIdx}"; if( ImGui.IsItemClicked( ImGuiMouseButton.Right ) )