mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-13 03:17:44 +01:00
Add collapsing to big option groups.
This commit is contained in:
parent
522fc832db
commit
21be245c5c
2 changed files with 78 additions and 28 deletions
2
OtterGui
2
OtterGui
|
|
@ -1 +1 @@
|
|||
Subproject commit 9e98cb9722bed3129134c7bc2fbe51268b2d6acd
|
||||
Subproject commit 95a26e944d550a3e77150667af00c23ef307b672
|
||||
|
|
@ -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 ) )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue