Skip to content

Commit

Permalink
Merge pull request #173 from Damon3000s/add-scoped-disabled
Browse files Browse the repository at this point in the history
Add scoped disabled
  • Loading branch information
matt-edmondson authored Feb 3, 2025
2 parents ccc3db5 + 1a89234 commit 2c3090f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ImGuiWidgets/ScopedDisable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ktsu.ImGuiWidgets;

using ImGuiNET;
using ScopedAction;

/// <summary>
/// Represents a scoped disable action which will set Dear ImGui elements as functionally and visually disabled until
/// the class is disposed.
/// </summary>
public class ScopedDisable : ScopedAction
{
/// <summary>
/// Note as per the Dear ImGui documentation: "Those can be nested, but it cannot
/// be used to enable an already disabled section (a single BeginDisabled(true)
/// in the stack is enough to keep everything disabled)"
/// </summary>
/// <param name="enabled">Should the elements within the scope be disabled</param>
public ScopedDisable(bool enabled)
{
ImGui.BeginDisabled(enabled);
OnClose = ImGui.EndDisabled;
}
}
13 changes: 13 additions & 0 deletions ImGuiWidgetsDemo/ImGuiWidgetsDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,19 @@ private void ShowLeftPanel(float size)
ImGuiWidgets.Combo("String Combo", ref selectedStringValue, possibleStringValues);
ImGuiWidgets.Combo("Strong String Combo", ref selectedStrongString, possibleStrongStringValues);


using (new ScopedDisable(true))
{
ImGui.SeparatorText("Disabled");

bool value = true;
int currentItem = 0;
string[] items = ["Item 1", "Item 2", "Item 3"];

ImGui.Checkbox("Disabled Checkbox", ref value);
ImGui.Combo("Disabled Combo", ref currentItem, items, items.Length);
}

ImGui.SeparatorText("Tree");
using (var tree = new ImGuiWidgets.Tree())
{
Expand Down

0 comments on commit 2c3090f

Please sign in to comment.