From 4e5d65bc07267919761ea9648a98c6fc34098a2e Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 15 Apr 2019 19:13:36 +0200 Subject: [PATCH] RangeSelect/MultiSelect: Added IMGUI_HAS_MULTI_SELECT define. Fixed right-click toggling selection without clearing active id, could lead to MarkItemEdited() asserting. Fixed demo. --- imgui.h | 2 ++ imgui_internal.h | 1 - imgui_widgets.cpp | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/imgui.h b/imgui.h index 722c3c1a..5788c4ae 100644 --- a/imgui.h +++ b/imgui.h @@ -2659,6 +2659,8 @@ struct ImColor // [SECTION] Multi-Select API flags and structures (ImGuiMultiSelectFlags, ImGuiMultiSelectData) //----------------------------------------------------------------------------- +#define IMGUI_HAS_MULTI_SELECT // Multi-Select/Range-Select WIP branch // <-- This is currently _not_ in the top of imgui.h to prevent merge conflicts. + // Flags for BeginMultiSelect(). // This system is designed to allow mouse/keyboard multi-selection, including support for range-selection (SHIFT + click) which is difficult to re-implement manually. // If you disable multi-selection with ImGuiMultiSelectFlags_NoMultiSelect (which is provided for consistency and flexibility), the whole BeginMultiSelect() system diff --git a/imgui_internal.h b/imgui_internal.h index 49ebbaaa..7e58208b 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1710,7 +1710,6 @@ struct ImGuiOldColumns // We always assume that -1 is an invalid value (which works for indices and pointers) #define ImGuiSelectionUserData_Invalid ((ImGuiSelectionUserData)-1) -#define IMGUI_HAS_MULTI_SELECT 1 #ifdef IMGUI_HAS_MULTI_SELECT struct IMGUI_API ImGuiMultiSelectState diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 218ff411..f5980419 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7141,7 +7141,9 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed) bool hovered = IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup); if (hovered && IsMouseClicked(1)) { - SetFocusID(g.LastItemData.ID, window); + if (g.ActiveId != 0 && g.ActiveId != id) + ClearActiveID(); + SetFocusID(id, window); if (!pressed && !selected) { pressed = true;