mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-14 20:54:16 +01:00
chore: add raii, tables code from OtterGui into new Dalamud.Interface assembly
This commit is contained in:
parent
e0d4e60aad
commit
6bf1376515
22 changed files with 1356 additions and 0 deletions
47
Dalamud.Interface/Table/ColumnSelect.cs
Normal file
47
Dalamud.Interface/Table/ColumnSelect.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using ImGuiNET;
|
||||
using ImRaii = Dalamud.Interface.Raii.ImRaii;
|
||||
|
||||
namespace Dalamud.Interface.Table;
|
||||
|
||||
public class ColumnSelect<T, TItem> : Column<TItem> where T : struct, Enum, IEquatable<T>
|
||||
{
|
||||
public ColumnSelect(T initialValue)
|
||||
=> this.FilterValue = initialValue;
|
||||
|
||||
protected virtual IReadOnlyList<T> Values
|
||||
=> Enum.GetValues<T>();
|
||||
|
||||
protected virtual string[] Names
|
||||
=> Enum.GetNames<T>();
|
||||
|
||||
protected virtual void SetValue(T value)
|
||||
=> this.FilterValue = value;
|
||||
|
||||
public T FilterValue;
|
||||
protected int Idx = -1;
|
||||
|
||||
public override bool DrawFilter()
|
||||
{
|
||||
using var id = ImRaii.PushId(this.FilterLabel);
|
||||
using var style = ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 0);
|
||||
ImGui.SetNextItemWidth(-Table.ArrowWidth * InterfaceHelpers.GlobalScale);
|
||||
using var combo = ImRaii.Combo(string.Empty, this.Idx < 0 ? this.Label : this.Names[this.Idx]);
|
||||
if(!combo)
|
||||
return false;
|
||||
|
||||
var ret = false;
|
||||
for (var i = 0; i < this.Names.Length; ++i)
|
||||
{
|
||||
if (this.FilterValue.Equals(this.Values[i]))
|
||||
this.Idx = i;
|
||||
if (!ImGui.Selectable(this.Names[i], this.Idx == i) || this.Idx == i)
|
||||
continue;
|
||||
|
||||
this.Idx = i;
|
||||
this.SetValue(this.Values[i]);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue