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,70 @@
using ImGuiNET;
namespace Dalamud.Interface.Raii;
public static partial class ImRaii
{
public static Indent PushIndent(float f, bool scaled = true, bool condition = true)
=> new Indent().Push(f, scaled, condition);
public static Indent PushIndent(int i = 1, bool condition = true)
=> new Indent().Push(i, condition);
public sealed class Indent : IDisposable
{
public float Indentation { get; private set; }
public Indent Push(float indent, bool scaled = true, bool condition = true)
{
if (condition)
{
if (scaled)
indent *= InterfaceHelpers.GlobalScale;
IndentInternal(indent);
this.Indentation += indent;
}
return this;
}
public Indent Push(int i = 1, bool condition = true)
{
if (condition)
{
var spacing = i * ImGui.GetStyle().IndentSpacing;
IndentInternal(spacing);
this.Indentation += spacing;
}
return this;
}
public void Pop(float indent, bool scaled = true)
{
if (scaled)
indent *= InterfaceHelpers.GlobalScale;
IndentInternal(-indent);
this.Indentation -= indent;
}
public void Pop(int i)
{
var spacing = i * ImGui.GetStyle().IndentSpacing;
IndentInternal(-spacing);
this.Indentation -= spacing;
}
private static void IndentInternal(float indent)
{
if (indent < 0)
ImGui.Unindent(-indent);
else if (indent > 0)
ImGui.Indent(indent);
}
public void Dispose()
=> this.Pop(this.Indentation, false);
}
}