From b444694b3d16c805200760098040c8a0085fd5e7 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 9 Apr 2026 21:36:50 +0200 Subject: [PATCH] Multi-Select: Box-Select: fixed an issue using ImGuiMultiSelectFlags_BoxSelect2d mode, where items out of view wouldn't be properly selected. (#7994, #1861, #6518) Because BoxSelectRectPrev and BoxSelectRectCurr were clamped to scope boundaries, dragging mouse outside of the scope would usually keep one axis unchanged. Amend 15391762ddbd4ad03c11dc1746f0603c75036edc --- docs/CHANGELOG.txt | 4 ++++ imgui_widgets.cpp | 16 +++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c6f9baa5d..148728e7b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -58,6 +58,10 @@ Other Changes: - Detect and report error when calling End() instead of EndPopup() on a popup. (#9351) - Child windows with only ImGuiChildFlags_AutoResizeY flag keep using the proportional default ItemWidth. (#9355) +- Multi-Select: + - Box-Select: fixed an issue using ImGuiMultiSelectFlags_BoxSelect2d mode, where + items out of view wouldn't be properly selected when scrolling while mouse cursor + is hovering outside of selection scope. (#7994, #1861, #6518) - Fonts: - imgui_freetype: add FreeType headers & compiled version in 'About Dear ImGui' details. - Clipper: diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 90484fa1b..bee85438f 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7836,15 +7836,17 @@ bool ImGui::BeginBoxSelect(const ImRect& scope_rect, ImGuiWindow* window, ImGuiI bs->BoxSelectRectCurr.Min = ImMin(start_pos_abs, curr_end_pos_abs); bs->BoxSelectRectCurr.Max = ImMax(start_pos_abs, curr_end_pos_abs); - // Box-select 2D mode detects horizontal changes (vertical ones are already picked by Clipper) - // Storing an extra rect used by widgets supporting box-select. + // Box-select 2D mode detects change of the rectangle. + // Storing unclip rect used by widgets supporting box-select. if (ms_flags & ImGuiMultiSelectFlags_BoxSelect2d) - if (bs->BoxSelectRectPrev.Min.x != bs->BoxSelectRectCurr.Min.x || bs->BoxSelectRectPrev.Max.x != bs->BoxSelectRectCurr.Max.x) - { + { + if (bs->BoxSelectRectPrev.Min != bs->BoxSelectRectCurr.Min || bs->BoxSelectRectPrev.Max != bs->BoxSelectRectCurr.Max) bs->UnclipMode = true; - bs->UnclipRect = bs->BoxSelectRectPrev; // FIXME-OPT: UnclipRect x coordinates could be intersection of Prev and Curr rect on X axis. - bs->UnclipRect.Add(bs->BoxSelectRectCurr); - } + + // Always update rect even if we don't use it. + bs->UnclipRect = bs->BoxSelectRectPrev; // FIXME-OPT: UnclipRect X coordinates could be intersection of Prev and Curr rect on X axis. + bs->UnclipRect.Add(bs->BoxSelectRectCurr); + } #ifdef IMGUI_DEBUG_BOXSELECT if (ms_flags & ImGuiMultiSelectFlags_BoxSelect2d)