Skip to content

Commit

Permalink
IsItemHovered(), ItemAdd(): Fixed seemingly unnecessary comparaison o…
Browse files Browse the repository at this point in the history
…f 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
  • Loading branch information
ocornut committed Sep 27, 2017
1 parent c075786 commit 344d48b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1948,16 +1948,14 @@ bool ImGui::ItemAdd(const ImRect& bb, const ImGuiID* id)
//if (g.IO.KeyAlt) window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255,255,0,120)); // [DEBUG]

// Set up for public-facing IsItemHovered(). We store the result in DC.LastItemHoveredAndUsable.
// This is roughly matching the behavior of internal IsHovered()
// This is roughly matching the behavior of internal-facing IsHovered()
// - 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())
// FIXME-OPT: Consider moving this code to IsItemHovered() so it's only evaluated if users needs it.
if (g.HoveredRootWindow == window->RootWindow)
{
if (g.HoveredWindow == window)
if (IsMouseHoveringRect(bb.Min, bb.Max))
if (g.ActiveId == 0 || (id && g.ActiveId == *id) || g.ActiveIdAllowOverlap || (g.ActiveId == window->MoveId))
if (IsWindowContentHoverable(window))
window->DC.LastItemHoveredAndUsable = true;
}

return true;
}
Expand All @@ -1982,9 +1980,10 @@ bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs)
{
ImGuiWindow* window = GetCurrentWindowRead();
if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow))
if ((g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) && IsMouseHoveringRect(bb.Min, bb.Max))
if (IsWindowContentHoverable(g.HoveredRootWindow))
return true;
if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap)
if (IsMouseHoveringRect(bb.Min, bb.Max))
if (IsWindowContentHoverable(g.HoveredRootWindow))
return true;
}
return false;
}
Expand Down

0 comments on commit 344d48b

Please sign in to comment.