// ReSharper disable once CheckNamespace
using Dalamud.Bindings.ImGui;
namespace Dalamud.Interface.Utility.Raii;
public static partial class ImRaii
{
/// A wrapper around creating pre-table style column separation.
public ref struct ColumnsDisposable : IDisposable
{
/// The columns before pushing this to revert to.
public readonly int LastColumns;
/// Get the current number of columns.
public int Count
=> ImGui.GetColumnsCount();
/// Get the index of the current column.
public int Current
=> ImGui.GetColumnIndex();
/// Move to the next column.
public void Next()
=> ImGui.NextColumn();
/// Get or set the offset of the current column.
public float Offset
{
get => ImGui.GetColumnOffset(Current);
set => ImGui.SetColumnOffset(Current, value);
}
/// Get the offset of a column by index.
public float GetOffset(int index)
=> ImGui.GetColumnOffset(index);
/// Set the offset of a column by index.
public void SetOffset(int index, float value)
=> ImGui.SetColumnOffset(index, value);
/// Get or set the width of the current column.
public float Width
{
get => ImGui.GetColumnWidth(Current);
set => ImGui.SetColumnWidth(Current, value);
}
/// Get the width of a column by index.
public float GetWidth(int index)
=> ImGui.GetColumnWidth(index);
/// Set the width of a column by index.
public void SetWidth(int index, float width)
=> ImGui.SetColumnWidth(index, width);
/// Create a new column separation.
/// The number of columns to separate.
/// An ID for the separation. If this is a UTF8 string, it HAS to be null-terminated.
/// Whether the columns should be separated by borders.
/// The columns system is outdated. Prefer to use instead.
public ColumnsDisposable(int count, ImU8String id, bool border = false)
{
this.LastColumns = this.Count;
ImGui.Columns(count, id, border);
}
/// Revert to the prior number of columns.
public void Dispose()
=> ImGui.Columns(Math.Max(this.LastColumns, 1));
}
}