Skip to content

Commit 3c20b54

Browse files
committed
Make mousewheel-scrolling work for setting combos, also filters.
1 parent 1961b03 commit 3c20b54

File tree

1 file changed

+50
-26
lines changed

1 file changed

+50
-26
lines changed

Penumbra/UI/ModsTab/Groups/ModGroupDrawer.cs

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,55 @@
1515

1616
namespace Penumbra.UI.ModsTab.Groups;
1717

18-
public sealed class ModGroupDrawer(Configuration config, CollectionManager collectionManager) : IUiService
18+
public sealed class ModGroupDrawer : IUiService
1919
{
2020
private readonly List<(IModGroup, int)> _blockGroupCache = [];
2121
private bool _temporary;
2222
private bool _locked;
2323
private TemporaryModSettings? _tempSettings;
2424
private ModSettings? _settings;
25+
private readonly SingleGroupCombo _combo;
26+
private readonly Configuration _config;
27+
private readonly CollectionManager _collectionManager;
28+
29+
public ModGroupDrawer(Configuration config, CollectionManager collectionManager)
30+
{
31+
_config = config;
32+
_collectionManager = collectionManager;
33+
_combo = new SingleGroupCombo(this);
34+
}
35+
36+
private sealed class SingleGroupCombo(ModGroupDrawer parent)
37+
: FilterComboCache<IModOption>(() => _group!.Options, MouseWheelType.Control, Penumbra.Log)
38+
{
39+
private static IModGroup? _group;
40+
private static int _groupIdx;
41+
42+
protected override bool DrawSelectable(int globalIdx, bool selected)
43+
{
44+
var option = _group!.Options[globalIdx];
45+
var ret = ImUtf8.Selectable(option.Name, globalIdx == CurrentSelectionIdx);
46+
47+
if (option.Description.Length > 0)
48+
ImUtf8.SelectableHelpMarker(option.Description);
49+
50+
return ret;
51+
}
52+
53+
protected override string ToString(IModOption obj)
54+
=> obj.Name;
55+
56+
public void Draw(IModGroup group, int groupIndex, int currentOption)
57+
{
58+
_group = group;
59+
_groupIdx = groupIndex;
60+
CurrentSelectionIdx = currentOption;
61+
CurrentSelection = _group.Options[CurrentSelectionIdx];
62+
if (Draw(string.Empty, CurrentSelection.Name, string.Empty, ref CurrentSelectionIdx, UiHelpers.InputTextWidth.X * 3 / 4,
63+
ImGui.GetTextLineHeightWithSpacing()))
64+
parent.SetModSetting(_group, _groupIdx, Setting.Single(CurrentSelectionIdx));
65+
}
66+
}
2567

2668
public void Draw(Mod mod, ModSettings settings, TemporaryModSettings? tempSettings)
2769
{
@@ -41,7 +83,7 @@ public void Draw(Mod mod, ModSettings settings, TemporaryModSettings? tempSettin
4183

4284
switch (group.Behaviour)
4385
{
44-
case GroupDrawBehaviour.SingleSelection when group.Options.Count <= config.SingleGroupRadioMax:
86+
case GroupDrawBehaviour.SingleSelection when group.Options.Count <= _config.SingleGroupRadioMax:
4587
case GroupDrawBehaviour.MultiSelection:
4688
_blockGroupCache.Add((group, idx));
4789
break;
@@ -76,25 +118,7 @@ private void DrawSingleGroupCombo(IModGroup group, int groupIdx, Setting setting
76118
using var id = ImUtf8.PushId(groupIdx);
77119
var selectedOption = setting.AsIndex;
78120
using var disabled = ImRaii.Disabled(_locked);
79-
ImGui.SetNextItemWidth(UiHelpers.InputTextWidth.X * 3 / 4);
80-
var options = group.Options;
81-
using (var combo = ImUtf8.Combo(""u8, options[selectedOption].Name))
82-
{
83-
if (combo)
84-
for (var idx2 = 0; idx2 < options.Count; ++idx2)
85-
{
86-
id.Push(idx2);
87-
var option = options[idx2];
88-
if (ImUtf8.Selectable(option.Name, idx2 == selectedOption))
89-
SetModSetting(group, groupIdx, Setting.Single(idx2));
90-
91-
if (option.Description.Length > 0)
92-
ImUtf8.SelectableHelpMarker(option.Description);
93-
94-
id.Pop();
95-
}
96-
}
97-
121+
_combo.Draw(group, groupIdx, selectedOption);
98122
ImGui.SameLine();
99123
if (group.Description.Length > 0)
100124
ImUtf8.LabeledHelpMarker(group.Name, group.Description);
@@ -195,7 +219,7 @@ private void DrawMultiPopup(IModGroup group, int groupIdx, string label)
195219

196220
private void DrawCollapseHandling(IReadOnlyList<IModOption> options, float minWidth, Action draw)
197221
{
198-
if (options.Count <= config.OptionGroupCollapsibleMin)
222+
if (options.Count <= _config.OptionGroupCollapsibleMin)
199223
{
200224
draw();
201225
}
@@ -240,21 +264,21 @@ private void DrawCollapseHandling(IReadOnlyList<IModOption> options, float minWi
240264
}
241265

242266
private ModCollection Current
243-
=> collectionManager.Active.Current;
267+
=> _collectionManager.Active.Current;
244268

245269
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
246270
private void SetModSetting(IModGroup group, int groupIdx, Setting setting)
247271
{
248-
if (_temporary || config.DefaultTemporaryMode)
272+
if (_temporary || _config.DefaultTemporaryMode)
249273
{
250274
_tempSettings ??= new TemporaryModSettings(group.Mod, _settings);
251275
_tempSettings!.ForceInherit = false;
252276
_tempSettings!.Settings[groupIdx] = setting;
253-
collectionManager.Editor.SetTemporarySettings(Current, group.Mod, _tempSettings);
277+
_collectionManager.Editor.SetTemporarySettings(Current, group.Mod, _tempSettings);
254278
}
255279
else
256280
{
257-
collectionManager.Editor.SetModSetting(Current, group.Mod, groupIdx, setting);
281+
_collectionManager.Editor.SetModSetting(Current, group.Mod, groupIdx, setting);
258282
}
259283
}
260284
}

0 commit comments

Comments
 (0)