Skip to content

Commit 0be238e

Browse files
committed
MultiSelect: Box-Select: fix preventing focus. amend determination of scope_hovered for decorated/non-child windows + avoid stealing NavId. (#7424)
1 parent e7a734f commit 0be238e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

imgui_widgets.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -7435,18 +7435,22 @@ ImGuiMultiSelectIO* ImGui::EndMultiSelect()
74357435

74367436
// Clear selection when clicking void?
74377437
// We specifically test for IsMouseDragPastThreshold(0) == false to allow box-selection!
7438-
bool scope_hovered = IsWindowHovered();
7438+
// The InnerRect test is necessary for non-child/decorated windows.
7439+
bool scope_hovered = IsWindowHovered() && window->InnerRect.Contains(g.IO.MousePos);
74397440
if (scope_hovered && (ms->Flags & ImGuiMultiSelectFlags_ScopeRect))
74407441
scope_hovered &= scope_rect.Contains(g.IO.MousePos);
74417442
if (scope_hovered && g.HoveredId == 0 && g.ActiveId == 0)
74427443
{
74437444
if (ms->Flags & ImGuiMultiSelectFlags_BoxSelect)
74447445
{
74457446
if (!g.BoxSelectState.IsActive && !g.BoxSelectState.IsStarting && g.IO.MouseClickedCount[0] == 1)
7447+
{
74467448
BoxSelectStartDrag(ms->BoxSelectId, ImGuiSelectionUserData_Invalid);
7447-
SetHoveredID(ms->BoxSelectId);
7448-
if (ms->Flags & ImGuiMultiSelectFlags_ScopeRect)
7449-
SetNavID(0, ImGuiNavLayer_Main, ms->FocusScopeId, ImRect(g.IO.MousePos, g.IO.MousePos)); // Automatically switch FocusScope for initial click from outside to box-select.
7449+
FocusWindow(window, ImGuiFocusRequestFlags_UnlessBelowModal);
7450+
SetHoveredID(ms->BoxSelectId);
7451+
if (ms->Flags & ImGuiMultiSelectFlags_ScopeRect)
7452+
SetNavID(0, ImGuiNavLayer_Main, ms->FocusScopeId, ImRect(g.IO.MousePos, g.IO.MousePos)); // Automatically switch FocusScope for initial click from void to box-select.
7453+
}
74507454
}
74517455

74527456
if (ms->Flags & ImGuiMultiSelectFlags_ClearOnClickVoid)

0 commit comments

Comments
 (0)