From a02d50099086d0e1088f7add4b447ff0786c8bd0 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 20 Aug 2020 20:46:57 +0200 Subject: [PATCH] RangeSelect/MultiSelect: Temporary fix/work-around for child/popup to not inherit MultiSelectEnabled flag, until we make mulit-select data stackable. --- imgui_demo.cpp | 10 +++++++++- imgui_internal.h | 6 +++--- imgui_widgets.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c8f34520..4806d390 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1272,7 +1272,7 @@ static void ShowDemoWindowWidgets() if (ImGui::RadioButton("Tree nodes", widget_type == WidgetType_TreeNode)) { widget_type = WidgetType_TreeNode; } ImGui::SameLine(); ImGui::Checkbox("Use 2 columns", &use_columns); - ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", (unsigned int*)&ImGui::GetIO().ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard); + ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", &ImGui::GetIO().ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard); ImGui::SameLine(); HelpMarker("Hold CTRL and click to select multiple items. Hold SHIFT to select a range. Keyboard is also supported."); // Open a scrolling region @@ -1333,6 +1333,14 @@ static void ShowDemoWindowWidgets() ImGui::TreePop(); } + // Right-click: context menu + if (ImGui::BeginPopupContextItem()) + { + ImGui::Text("(Testing Selectable inside an embedded popup)"); + ImGui::Selectable("Close"); + ImGui::EndPopup(); + } + if (use_columns) { ImGui::NextColumn(); diff --git a/imgui_internal.h b/imgui_internal.h index 4b8b1ea4..1e0281d5 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1718,9 +1718,9 @@ struct ImGuiContext bool NavWindowingToggleLayer; // Range-Select/Multi-Select - bool MultiSelectEnabled; + ImGuiWindow* MultiSelectEnabledWindow; // FIXME-MULTISELECT: We currently don't support recursing/stacking multi-select ImGuiMultiSelectFlags MultiSelectFlags; - ImGuiMultiSelectState MultiSelectState; // We currently don't support recursing/stacking multi-select + ImGuiMultiSelectState MultiSelectState; ImGuiKeyModFlags MultiSelectKeyMods; // Render @@ -1919,7 +1919,7 @@ struct ImGuiContext NavWindowingTimer = NavWindowingHighlightAlpha = 0.0f; NavWindowingToggleLayer = false; - MultiSelectEnabled = false; + MultiSelectEnabledWindow = NULL; MultiSelectFlags = ImGuiMultiSelectFlags_None; MultiSelectKeyMods = ImGuiKeyModFlags_None; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 65d778d4..09c53769 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5922,7 +5922,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l const bool was_selected = selected; // Multi-selection support (header) - const bool is_multi_select = g.MultiSelectEnabled; + const bool is_multi_select = (g.MultiSelectEnabledWindow == window); if (is_multi_select) { MultiSelectItemHeader(id, &selected); @@ -6255,7 +6255,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (flags & ImGuiSelectableFlags_AllowItemOverlap) { button_flags |= ImGuiButtonFlags_AllowItemOverlap; } // Multi-selection support (header) - const bool is_multi_select = g.MultiSelectEnabled; + const bool is_multi_select = (g.MultiSelectEnabledWindow == window); const bool was_selected = selected; if (is_multi_select) { @@ -6375,7 +6375,7 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void* ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - IM_ASSERT(g.MultiSelectEnabled == false); // No recursion allowed yet (we could allow it if we deem it useful) + IM_ASSERT(g.MultiSelectEnabledWindow == NULL); // No recursion allowed yet (we could allow it if we deem it useful) IM_ASSERT(g.MultiSelectFlags == 0); IM_ASSERT(g.MultiSelectState.FocusScopeId == 0); @@ -6384,7 +6384,7 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void* state->Clear(); state->BackupFocusScopeId = window->DC.NavFocusScopeIdCurrent; state->FocusScopeId = window->DC.NavFocusScopeIdCurrent = window->IDStack.back(); - g.MultiSelectEnabled = true; + g.MultiSelectEnabledWindow = window; g.MultiSelectFlags = flags; // Use copy of keyboard mods at the time of the request, otherwise we would requires mods to be held for an extra frame. @@ -6434,7 +6434,7 @@ ImGuiMultiSelectData* ImGui::EndMultiSelect() state->Out.RangeValue = true; g.MultiSelectState.FocusScopeId = 0; window->DC.NavFocusScopeIdCurrent = g.MultiSelectState.BackupFocusScopeId; - g.MultiSelectEnabled = false; + g.MultiSelectEnabledWindow = NULL; g.MultiSelectFlags = ImGuiMultiSelectFlags_None; #ifdef IMGUI_DEBUG_MULTISELECT