From 9b925d51bbc51cc4bd18acbf2b437330a0d5de02 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 10 Apr 2019 15:24:49 +0200 Subject: [PATCH] RangeSelect/MultiSelect: Fix so that shift+arrow when landing on an item that doesn't hold multi-select data doesn't trigger an unbounded range-select that ends up selecting everything until the end. --- imgui_internal.h | 2 +- imgui_widgets.cpp | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/imgui_internal.h b/imgui_internal.h index 1a22d270..ccb10d39 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1094,7 +1094,7 @@ struct ImGuiNextItemData ImGuiID FocusScopeId; // Set by SetNextItemMultiSelectData() (!= 0 signify value has been set, so it's an alternate version of HasSelectionData, we don't use Flags for this because they are cleared too early. This is mostly used for debugging) ImGuiCond OpenCond; bool OpenVal; // Set by SetNextItemOpen() - bool MultiSelectDataIsSet; + ImGuiID MultiSelectScopeId; void* MultiSelectData; ImGuiNextItemData() { memset(this, 0, sizeof(*this)); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index e354cb76..1bb501ba 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6363,6 +6363,9 @@ bool ImGui::Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags // - MultiSelectItemHeader() [Internal] // - MultiSelectItemFooter() [Internal] //------------------------------------------------------------------------- +// FIXME: Shift+click on an item that has no multi-select data could treat selection the same as the last item with such data? +// The problem is that this may conflict with other behaviors of those items? +//------------------------------------------------------------------------- ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void* range_ref, bool range_ref_is_selected) { @@ -6429,8 +6432,9 @@ ImGuiMultiSelectData* ImGui::EndMultiSelect() void ImGui::SetNextItemMultiSelectData(void* item_data) { ImGuiContext& g = *GImGui; + IM_ASSERT(g.MultiSelectScopeId != 0); g.NextItemData.MultiSelectData = item_data; - g.NextItemData.MultiSelectDataIsSet = true; + g.NextItemData.MultiSelectScopeId = g.MultiSelectScopeId; } void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected) @@ -6438,7 +6442,7 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected) ImGuiContext& g = *GImGui; ImGuiMultiSelectState* state = &g.MultiSelectState; - IM_ASSERT(g.NextItemData.MultiSelectDataIsSet && "Forgot to call SetNextItemMultiSelectData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope"); + IM_ASSERT(g.NextItemData.MultiSelectScopeId == g.MultiSelectScopeId && "Forgot to call SetNextItemMultiSelectData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope"); void* item_data = g.NextItemData.MultiSelectData; // Apply Clear/SelectAll requests requested by BeginMultiSelect(). @@ -6479,7 +6483,7 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed) ImGuiMultiSelectState* state = &g.MultiSelectState; void* item_data = g.NextItemData.MultiSelectData; - g.NextItemData.MultiSelectDataIsSet = false; + g.NextItemData.MultiSelectScopeId = 0; bool selected = *p_selected; bool pressed = *p_pressed;