Add option to expand or collapse all sub-folders in the right-click context for mod folders.

This commit is contained in:
Ottermandias 2022-03-08 10:09:34 +01:00
parent 6df82fdf18
commit bf40c2a3cb

View file

@ -14,10 +14,10 @@ using Penumbra.Mods;
using Penumbra.UI.Custom;
using Penumbra.Util;
namespace Penumbra.UI
namespace Penumbra.UI;
public partial class SettingsInterface
{
public partial class SettingsInterface
{
// Constants
private partial class Selector
{
@ -37,10 +37,10 @@ namespace Penumbra.UI
private const float SelectorPanelWidth = 240f;
private static readonly Vector2 SelectorButtonSizes = new( 100, 0 );
private static readonly Vector2 HelpButtonSizes = new( 40, 0 );
private static readonly Vector2 SelectorButtonSizes = new(100, 0);
private static readonly Vector2 HelpButtonSizes = new(40, 0);
private static readonly Vector4 DeleteModNameColor = new( 0.7f, 0.1f, 0.1f, 1 );
private static readonly Vector4 DeleteModNameColor = new(0.7f, 0.1f, 0.1f, 1);
}
// Buttons
@ -501,6 +501,9 @@ namespace Penumbra.UI
// === Folder ===
private string _newFolderName = string.Empty;
private int _expandIndex = -1;
private bool _expandCollapse;
private bool _currentlyExpanding;
private void ChangeStatusOfChildren( ModFolder folder, int currentIdx, bool toWhat )
{
@ -563,6 +566,18 @@ namespace Penumbra.UI
using var raii = ImGuiRaii.DeferredEnd( ImGui.EndPopup );
if( ImGui.MenuItem( "Expand All Descendants" ) )
{
_expandIndex = currentIdx;
_expandCollapse = false;
}
if( ImGui.MenuItem( "Collapse All Descendants" ) )
{
_expandIndex = currentIdx;
_expandCollapse = true;
}
if( ImGui.MenuItem( "Enable All Descendants" ) )
{
ChangeStatusOfChildren( folder, currentIdx, true );
@ -674,6 +689,17 @@ namespace Penumbra.UI
var treeName = $"{folder.Name}##{folder.FullName}";
var open = ImGui.TreeNodeEx( treeName );
using var raii = ImGuiRaii.DeferredEnd( ImGui.TreePop, open );
if( idx == _expandIndex )
{
_currentlyExpanding = true;
}
if( _currentlyExpanding )
{
ImGui.SetNextItemOpen( !_expandCollapse );
}
if( ImGui.IsItemClicked( ImGuiMouseButton.Right ) )
{
_newFolderName = string.Empty;
@ -692,6 +718,12 @@ namespace Penumbra.UI
{
idx += folder.TotalDescendantMods();
}
if( idx == _expandIndex )
{
_currentlyExpanding = false;
_expandIndex = -1;
}
}
private void DrawMod( Mod.Mod mod, int modIndex, uint color )
@ -767,5 +799,4 @@ namespace Penumbra.UI
DrawDeleteModal();
}
}
}
}