chore: add raii, tables code from OtterGui into new Dalamud.Interface assembly

This commit is contained in:
goat 2023-03-06 20:52:21 +01:00
parent e0d4e60aad
commit 6bf1376515
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
22 changed files with 1356 additions and 0 deletions

View file

@ -0,0 +1,56 @@
using System.Text.RegularExpressions;
using Dalamud.Interface.Raii;
using ImGuiNET;
namespace Dalamud.Interface.Table;
public class ColumnString<TItem> : Column<TItem>
{
public ColumnString()
=> this.Flags &= ~ImGuiTableColumnFlags.NoResize;
public string FilterValue = string.Empty;
protected Regex? FilterRegex;
public virtual string ToName(TItem item)
=> item!.ToString() ?? string.Empty;
public override int Compare(TItem lhs, TItem rhs)
=> string.Compare(this.ToName(lhs), this.ToName(rhs), StringComparison.InvariantCulture);
public override bool DrawFilter()
{
using var style = ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 0);
ImGui.SetNextItemWidth(-Table.ArrowWidth * InterfaceHelpers.GlobalScale);
var tmp = this.FilterValue;
if (!ImGui.InputTextWithHint(this.FilterLabel, this.Label, ref tmp, 256) || tmp == this.FilterValue)
return false;
this.FilterValue = tmp;
try
{
this.FilterRegex = new Regex(this.FilterValue, RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
}
catch
{
this.FilterRegex = null;
}
return true;
}
public override bool FilterFunc(TItem item)
{
var name = this.ToName(item);
if (this.FilterValue.Length == 0)
return true;
return this.FilterRegex?.IsMatch(name) ?? name.Contains(this.FilterValue, StringComparison.OrdinalIgnoreCase);
}
public override void DrawColumn(TItem item, int _)
{
ImGui.TextUnformatted(this.ToName(item));
}
}