Make collection combo mousewheel-scrollable with ctrl.

This commit is contained in:
Ottermandias 2024-08-12 20:57:38 +02:00
parent 6e351aa68b
commit 3135d5e7e6

View file

@ -1,14 +1,15 @@
using ImGuiNET;
using OtterGui;
using OtterGui.Raii;
using OtterGui.Text;
using OtterGui.Widgets;
using Penumbra.Collections;
using Penumbra.Collections.Manager;
using Penumbra.GameData.Actors;
namespace Penumbra.UI.CollectionTab;
public sealed class CollectionCombo(CollectionManager manager, Func<IReadOnlyList<ModCollection>> items)
: FilterComboCache<ModCollection>(items, MouseWheelType.None, Penumbra.Log)
: FilterComboCache<ModCollection>(items, MouseWheelType.Control, Penumbra.Log)
{
private readonly ImRaii.Color _color = new();
@ -20,14 +21,26 @@ public sealed class CollectionCombo(CollectionManager manager, Func<IReadOnlyLis
public void Draw(string label, float width, uint color)
{
var current = manager.Active.ByType(CollectionType.Current, ActorIdentifier.Invalid);
_color.Push(ImGuiCol.FrameBg, color).Push(ImGuiCol.FrameBgHovered, color);
var current = manager.Active.Current;
if (current != CurrentSelection)
{
CurrentSelectionIdx = Items.IndexOf(current);
UpdateSelection(current);
}
if (Draw(label, current?.Name ?? string.Empty, string.Empty, width, ImGui.GetTextLineHeightWithSpacing()) && CurrentSelection != null)
_color.Push(ImGuiCol.FrameBg, color).Push(ImGuiCol.FrameBgHovered, color);
if (Draw(label, current.Name, string.Empty, width, ImGui.GetTextLineHeightWithSpacing()) && CurrentSelection != null)
manager.Active.SetCollection(CurrentSelection, CollectionType.Current);
_color.Dispose();
}
protected override string ToString(ModCollection obj)
=> obj.Name;
protected override void DrawCombo(string label, string preview, string tooltip, int currentSelected, float previewWidth, float itemHeight,
ImGuiComboFlags flags)
{
base.DrawCombo(label, preview, tooltip, currentSelected, previewWidth, itemHeight, flags);
ImUtf8.HoverTooltip("Control and mouse wheel to scroll."u8);
}
}