From 85a7202129d9e054f221f65c1e96b7ac664f396b Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 12 Apr 2023 22:14:32 +0200 Subject: [PATCH] RangeSelect/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 421af5e3..4853fb20 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -2861,10 +2861,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 7a753cc8..9f7a2beb 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7101,6 +7101,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) @@ -7123,16 +7127,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;