// ReSharper disable once CheckNamespace using Dalamud.Bindings.ImGui; namespace Dalamud.Interface.Utility.Raii; public static partial class ImRaii { /// A wrapper around disabled state. public sealed class DisabledDisposable : IDisposable { /// The global count of disabled pushes to reenable. public static int GlobalCount; /// Gets the number of disabled states currently pushed using this disposable. public int Count { get; private set; } /// Push a disabled state onto the stack. /// Whether to actually push a disabled state. /// A disposable object that can be used to push further disabled states for whatever reason and pop them on leaving scope. Use with using. /// If you need to keep a disabled state pushed longer than the current scope, use without using and use . public DisabledDisposable Push(bool condition) => condition ? this.Push() : this; /// public DisabledDisposable Push() { ImGui.BeginDisabled(true); ++this.Count; ++GlobalCount; return this; } /// Pop a number of disabled states. /// The number of disabled states to pop. This is clamped to the number of disabled states pushed by this object. public void Pop(int num = 1) { num = Math.Min(num, this.Count); this.Count -= num; GlobalCount -= num; while (num-- > 0) ImGui.EndDisabled(); } /// Pop all disabled states. public void Dispose() => this.Pop(this.Count); /// Pop a number of disabled states. /// The number of disabled states to pop. The number is not checked against the disabled stack. /// Avoid using this function, and disabled states across scopes, as much as possible. public static void PopUnsafe(int num = 1) { while (num-- > 0) ImGui.EndDisabled(); } } }