mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 06:13:40 +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
70
Dalamud.Interface/Raii/Indent.cs
Normal file
70
Dalamud.Interface/Raii/Indent.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue