Skip to content

Commit 344d48b

Browse files
committed
IsItemHovered(), ItemAdd(): Fixed seemingly unnecessary comparaison of root windows, makes IsItemHovered() more consistent with internal IsHovered().
Original test was added in 6e99688 should not have been using RootWindow in the first place. The difference between public-facing and internal versions would only be noticeable with overlapped child windows, which doesn't really happen anyway
1 parent c075786 commit 344d48b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

imgui.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,16 +1948,14 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id)
19481948
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]
19491949

19501950
// Set up for public-facing IsItemHovered(). We store the result in DC.LastItemHoveredAndUsable.
1951-
// This is roughly matching the behavior of internal IsHovered()
1951+
// This is roughly matching the behavior of internal-facing IsHovered()
19521952
// - we allow hovering to be true when ActiveId==window->MoveID, so that clicking on non-interactive items such as a Text() item still returns true with IsItemHovered())
19531953
// FIXME-OPT: Consider moving this code to IsItemHovered() so it's only evaluated if users needs it.
1954-
if (g.HoveredRootWindow == window->RootWindow)
1955-
{
1954+
if (g.HoveredWindow == window)
19561955
if (IsMouseHoveringRect(bb.Min, bb.Max))
19571956
if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdAllowOverlap || (g.ActiveId == window->MoveId))
19581957
if (IsWindowContentHoverable(window))
19591958
window->DC.LastItemHoveredAndUsable = true;
1960-
}
19611959

19621960
return true;
19631961
}
@@ -1982,9 +1980,10 @@ bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs)
19821980
{
19831981
ImGuiWindow* window = GetCurrentWindowRead();
19841982
if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
1985-
if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) && IsMouseHoveringRect(bb.Min, bb.Max))
1986-
if (IsWindowContentHoverable(g.HoveredRootWindow))
1987-
return true;
1983+
if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap)
1984+
if (IsMouseHoveringRect(bb.Min, bb.Max))
1985+
if (IsWindowContentHoverable(g.HoveredRootWindow))
1986+
return true;
19881987
}
19891988
return false;
19901989
}

0 commit comments

Comments
 (0)