From 815c61b82eb5f00ea8eb0a772b646306a25dd2d2 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 12 Apr 2023 22:14:32 +0200 Subject: [PATCH] MultiSelect: Fixed needing to set RangeSrcPassedBy when not using clipper. --- imgui_demo.cpp | 4 ---- imgui_widgets.cpp | 9 +++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index c8fc424dc..3b98bc5c4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2881,10 +2881,6 @@ static void ShowDemoWindowMultiSelect() for (int n = 0; n < ITEMS_COUNT; n++) { - // FIXME-MULTISELECT: This should not be needed but currently is because coarse clipping break the auto-setup. - if (n > selection.RangeRef) - multi_select_data->RangeSrcPassedBy = true; - char label[64]; sprintf(label, "Object %05d: %s", n, random_names[n % IM_ARRAYSIZE(random_names)]); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 5da30ea2e..f1da8b168 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7218,6 +7218,10 @@ void ImGui::SetNextItemSelectionUserData(ImGuiSelectionUserData selection_user_d g.NextItemData.ItemFlags |= ImGuiItemFlags_HasSelectionUserData; g.NextItemData.SelectionUserData = selection_user_data; g.NextItemData.FocusScopeId = g.CurrentFocusScopeId; + + // Auto updating RangeSrcPassedBy for cases were clipped is not used. + if (g.MultiSelectState.In.RangeSrc == (void*)selection_user_data) + g.MultiSelectState.In.RangeSrcPassedBy = true; } void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected) @@ -7240,16 +7244,13 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected) else if (ms->In.RequestSelectAll) selected = true; - const bool is_range_src = (ms->In.RangeSrc == item_data); - if (is_range_src) - ms->In.RangeSrcPassedBy = true; // FIXME-MULTISELECT: The promise that this would be automatically done is not because of ItemAdd() clipping. - // When using SHIFT+Nav: because it can incur scrolling we cannot afford a frame of lag with the selection highlight (otherwise scrolling would happen before selection) // For this to work, IF the user is clipping items, they need to set RangeSrcPassedBy = true to notify the system. if (ms->InRequestSetRangeNav) { IM_ASSERT(id != 0); IM_ASSERT((ms->KeyMods & ImGuiMod_Shift) != 0); + const bool is_range_src = (ms->In.RangeSrc == item_data); const bool is_range_dst = !ms->InRangeDstPassedBy && g.NavJustMovedToId == id; // Assume that g.NavJustMovedToId is not clipped. if (is_range_dst) ms->InRangeDstPassedBy = true;