MCPcopy Create free account
hub / github.com/KebsCS/KBotExt / IsItemHovered

Method IsItemHovered

KBotExt/imgui/imgui.cpp:3985–4071  ·  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

3983// - 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()
3984// - this should work even for non-interactive items that have no ID, so we cannot use LastItemId
3985bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
3986{
3987 ImGuiContext& g = *GImGui;
3988 ImGuiWindow* window = g.CurrentWindow;
3989 IM_ASSERT((flags & ~ImGuiHoveredFlags_AllowedMaskForIsItemHovered) == 0 && "Invalid flags for IsItemHovered()!");
3990
3991 if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride))
3992 {
3993 if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
3994 return false;
3995 if (!IsItemFocused())
3996 return false;
3997
3998 if (flags & ImGuiHoveredFlags_ForTooltip)
3999 flags |= g.Style.HoverFlagsForTooltipNav;
4000 }
4001 else
4002 {
4003 // Test for bounding box overlap, as updated as ItemAdd()
4004 ImGuiItemStatusFlags status_flags = g.LastItemData.StatusFlags;
4005 if (!(status_flags & ImGuiItemStatusFlags_HoveredRect))
4006 return false;
4007
4008 if (flags & ImGuiHoveredFlags_ForTooltip)
4009 flags |= g.Style.HoverFlagsForTooltipMouse;
4010
4011 IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
4012
4013 // Done with rectangle culling so we can perform heavier checks now
4014 // Test if we are hovering the right window (our window could be behind another window)
4015 // [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
4016 // [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
4017 // 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
4018 // the test that has been running for a long while.
4019 if (g.HoveredWindow != window && (status_flags & ImGuiItemStatusFlags_HoveredWindow) == 0)
4020 if ((flags & ImGuiHoveredFlags_AllowWhenOverlappedByWindow) == 0)
4021 return false;
4022
4023 // Test if another item is active (e.g. being dragged)
4024 const ImGuiID id = g.LastItemData.ID;
4025 if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0)
4026 if (g.ActiveId != 0 && g.ActiveId != id && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId)
4027 return false;
4028
4029 // Test if interactions on this window are blocked by an active popup or modal.
4030 // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
4031 if (!IsWindowContentHoverable(window, flags) && !(g.LastItemData.InFlags & ImGuiItemFlags_NoWindowHoverableCheck))
4032 return false;
4033
4034 // Test if the item is disabled
4035 if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
4036 return false;
4037
4038 // Special handling for calling after Begin() which represent the title bar or tab.
4039 // When the window is skipped/collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
4040 if (id == window->MoveId && window->WriteAccessed)
4041 return false;
4042

Callers

nothing calls this directly

Calls 2

GetIDFromRectangleMethod · 0.80

Tested by

no test coverage detected