MCPcopy Create free account
hub / github.com/RenderKit/embree / IsItemHovered

Method IsItemHovered

tutorials/common/imgui/imgui.cpp:3629–3697  ·  view source on GitHub ↗

This is roughly matching the behavior of internal-facing ItemHoverable() - 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() - this should work even for non-interactive items that have no ID, so we cannot use LastItemId

Source from the content-addressed store, hash-verified

3627// - 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()
3628// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId
3629bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
3630{
3631 ImGuiContext& g = *GImGui;
3632 ImGuiWindow* window = g.CurrentWindow;
3633 if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride))
3634 {
3635 if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
3636 return false;
3637 if (!IsItemFocused())
3638 return false;
3639 }
3640 else
3641 {
3642 // Test for bounding box overlap, as updated as ItemAdd()
3643 ImGuiItemStatusFlags status_flags = g.LastItemData.StatusFlags;
3644 if (!(status_flags & ImGuiItemStatusFlags_HoveredRect))
3645 return false;
3646 IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
3647
3648 // Done with rectangle culling so we can perform heavier checks now
3649 // Test if we are hovering the right window (our window could be behind another window)
3650 // [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
3651 // [2017/10/16] Reverted commit 344d48be3 and testing RootWindow instead. I believe it is correct to NOT test for RootWindow but this leaves us unable
3652 // to use IsItemHovered() after EndChild() itself. Until a solution is found I believe reverting to the test from 2017/09/27 is safe since this was
3653 // the test that has been running for a long while.
3654 if (g.HoveredWindow != window && (status_flags & ImGuiItemStatusFlags_HoveredWindow) == 0)
3655 if ((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0)
3656 return false;
3657
3658 // Test if another item is active (e.g. being dragged)
3659 if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0)
3660 if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId)
3661 return false;
3662
3663 // Test if interactions on this window are blocked by an active popup or modal.
3664 // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
3665 if (!IsWindowContentHoverable(window, flags) && !(g.LastItemData.InFlags & ImGuiItemFlags_NoWindowHoverableCheck))
3666 return false;
3667
3668 // Test if the item is disabled
3669 if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
3670 return false;
3671
3672 // Special handling for calling after Begin() which represent the title bar or tab.
3673 // When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
3674 if (g.LastItemData.ID == window->MoveId && window->WriteAccessed)
3675 return false;
3676 }
3677
3678 // Handle hover delay
3679 // (some ideas: https://www.nngroup.com/articles/timing-exposing-content)
3680 float delay;
3681 if (flags & ImGuiHoveredFlags_DelayNormal)
3682 delay = g.IO.HoverDelayNormal;
3683 else if (flags & ImGuiHoveredFlags_DelayShort)
3684 delay = g.IO.HoverDelayShort;
3685 else
3686 delay = 0.0f;

Callers

nothing calls this directly

Calls 2

IsWindowContentHoverableFunction · 0.85
GetIDFromRectangleMethod · 0.80

Tested by

no test coverage detected