From 24677c561e6a50c97daa1f6e7ff2b042fddd0ccf Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 9 Apr 2026 21:02:01 +0200 Subject: [PATCH] Multi-Select: Box-Select: add compile-time debug options. (#7994, #1861, #6518) --- imgui_internal.h | 3 +++ imgui_widgets.cpp | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/imgui_internal.h b/imgui_internal.h index bb0b7f3a3..2a51931ef 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -252,6 +252,9 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit context pointer #define IMGUI_DEBUG_LOG_FONT(...) do { ImGuiContext* g2 = GImGui; if (g2 && g2->DebugLogFlags & ImGuiDebugLogFlags_EventFont) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) // Called from ImFontAtlas function which may operate without a context. #define IMGUI_DEBUG_LOG_INPUTROUTING(...) do{if (g.DebugLogFlags & ImGuiDebugLogFlags_EventInputRouting)IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +// Debug options (also see ones on top of imgui.cpp) +//#define IMGUI_DEBUG_BOXSELECT + // Static Asserts #define IM_STATIC_ASSERT(_COND) static_assert(_COND, "") diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3483acb6c..90484fa1b 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7505,6 +7505,11 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (is_visible) RenderTextClipped(pos, ImVec2(ImMin(pos.x + size.x, window->WorkRect.Max.x), pos.y + size.y), label, NULL, &label_size, style.SelectableTextAlign, &bb); +#ifdef IMGUI_DEBUG_BOXSELECT + if (g.BoxSelectState.UnclipMode) + GetForegroundDrawList()->AddText(pos, IM_COL32(255,255,0,200), label); +#endif + // Automatically close popups if (pressed && !auto_selected && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_NoAutoClosePopups) && (g.LastItemData.ItemFlags & ImGuiItemFlags_AutoClosePopups)) CloseCurrentPopup(); @@ -7841,9 +7846,12 @@ bool ImGui::BeginBoxSelect(const ImRect& scope_rect, ImGuiWindow* window, ImGuiI bs->UnclipRect.Add(bs->BoxSelectRectCurr); } - //GetForegroundDrawList()->AddRect(bs->UnclipRect.Min, bs->UnclipRect.Max, IM_COL32(255,0,0,200), 0.0f, 0, 3.0f); +#ifdef IMGUI_DEBUG_BOXSELECT + if (ms_flags & ImGuiMultiSelectFlags_BoxSelect2d) + GetForegroundDrawList()->AddRect(bs->UnclipRect.Min, bs->UnclipRect.Max, bs->UnclipMode ? IM_COL32(255,255,0,200) : IM_COL32(255,0,0,200), 0.0f, 0, 4.0f); //GetForegroundDrawList()->AddRect(bs->BoxSelectRectPrev.Min, bs->BoxSelectRectPrev.Max, IM_COL32(255,0,0,200), 0.0f, 0, 3.0f); //GetForegroundDrawList()->AddRect(bs->BoxSelectRectCurr.Min, bs->BoxSelectRectCurr.Max, IM_COL32(0,255,0,200), 0.0f, 0, 1.0f); +#endif return true; } @@ -8304,6 +8312,9 @@ void ImGui::MultiSelectItemFooter(ImGuiID id, bool* p_selected, bool* p_pressed) { selected = !selected; MultiSelectAddSetRange(ms, selected, +1, item_data, item_data); +#ifdef IMGUI_DEBUG_BOXSELECT + GetForegroundDrawList()->AddRectFilled(g.LastItemData.Rect.Min, g.LastItemData.Rect.Max, selected ? IM_COL32(0, 255, 0, 200) : IM_COL32(255, 0, 0, 200)); +#endif } storage->LastSelectionSize = ImMax(storage->LastSelectionSize + 1, 1); }