mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 12:23:39 +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
66
Dalamud.Interface/Raii/Id.cs
Normal file
66
Dalamud.Interface/Raii/Id.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using ImGuiNET;
|
||||
|
||||
namespace Dalamud.Interface.Raii;
|
||||
|
||||
// Push an arbitrary amount of ids into an object that are all popped when it is disposed.
|
||||
// If condition is false, no id is pushed.
|
||||
public static partial class ImRaii
|
||||
{
|
||||
public static Id PushId(string id, bool enabled = true)
|
||||
=> enabled ? new Id().Push(id) : new Id();
|
||||
|
||||
public static Id PushId(int id, bool enabled = true)
|
||||
=> enabled ? new Id().Push(id) : new Id();
|
||||
|
||||
public static Id PushId(IntPtr id, bool enabled = true)
|
||||
=> enabled ? new Id().Push(id) : new Id();
|
||||
|
||||
public sealed class Id : IDisposable
|
||||
{
|
||||
private int _count;
|
||||
|
||||
public Id Push(string id, bool condition = true)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
ImGui.PushID(id);
|
||||
++this._count;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Id Push(int id, bool condition = true)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
ImGui.PushID(id);
|
||||
++this._count;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Id Push(IntPtr id, bool condition = true)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
ImGui.PushID(id);
|
||||
++this._count;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Pop(int num = 1)
|
||||
{
|
||||
num = Math.Min(num, this._count);
|
||||
this._count -= num;
|
||||
while (num-- > 0)
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
=> this.Pop(this._count);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue