MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / IsItemHovered

Method IsItemHovered

extern/imgui/imgui.cpp:3715–3785  ·  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

3713// - 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()
3714// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId
3715bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
3716{
3717 ImGuiContext& g = *GImGui;
3718 ImGuiWindow* window = g.CurrentWindow;
3719 if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride))
3720 {
3721 if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
3722 return false;
3723 if (!IsItemFocused())
3724 return false;
3725 }
3726 else
3727 {
3728 // Test for bounding box overlap, as updated as ItemAdd()
3729 ImGuiItemStatusFlags status_flags = g.LastItemData.StatusFlags;
3730 if (!(status_flags & ImGuiItemStatusFlags_HoveredRect))
3731 return false;
3732 IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy | ImGuiHoveredFlags_DockHierarchy)) == 0); // Flags not supported by this function
3733
3734 // Done with rectangle culling so we can perform heavier checks now
3735 // Test if we are hovering the right window (our window could be behind another window)
3736 // [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
3737 // [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
3738 // 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
3739 // the test that has been running for a long while.
3740 if (g.HoveredWindow != window && (status_flags & ImGuiItemStatusFlags_HoveredWindow) == 0)
3741 if ((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0)
3742 return false;
3743
3744 // Test if another item is active (e.g. being dragged)
3745 if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0)
3746 if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap)
3747 if (g.ActiveId != window->MoveId && g.ActiveId != window->TabId)
3748 return false;
3749
3750 // Test if interactions on this window are blocked by an active popup or modal.
3751 // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
3752 if (!IsWindowContentHoverable(window, flags) && !(g.LastItemData.InFlags & ImGuiItemFlags_NoWindowHoverableCheck))
3753 return false;
3754
3755 // Test if the item is disabled
3756 if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
3757 return false;
3758
3759 // Special handling for calling after Begin() which represent the title bar or tab.
3760 // When the window is skipped/collapsed (SkipItems==true) that last item (always ->MoveId submitted by Begin)
3761 // will never be overwritten so we need to detect the case.
3762 if (g.LastItemData.ID == window->MoveId && window->WriteAccessed)
3763 return false;
3764 }
3765
3766 // Handle hover delay
3767 // (some ideas: https://www.nngroup.com/articles/timing-exposing-content)
3768 float delay;
3769 if (flags & ImGuiHoveredFlags_DelayNormal)
3770 delay = g.IO.HoverDelayNormal;
3771 else if (flags & ImGuiHoveredFlags_DelayShort)
3772 delay = g.IO.HoverDelayShort;

Callers

nothing calls this directly

Calls 2

IsWindowContentHoverableFunction · 0.85
GetIDFromRectangleMethod · 0.80

Tested by

no test coverage detected