Internals: move chunks of IsItemHovered() so upcoming commit can be less noisy. This commit should be a no-op (check by comparing without white-space changes)

docking
ocornut 3 years ago
parent 2c29e391dd
commit d80a9123b7

@ -3278,42 +3278,46 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags)
{ {
if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled)) if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
return false; return false;
return IsItemFocused(); if (!IsItemFocused())
return false;
} }
else
// Test for bounding box overlap, as updated as ItemAdd() {
ImGuiItemStatusFlags status_flags = g.LastItemData.StatusFlags; // Test for bounding box overlap, as updated as ItemAdd()
if (!(status_flags & ImGuiItemStatusFlags_HoveredRect)) ImGuiItemStatusFlags status_flags = g.LastItemData.StatusFlags;
return false; if (!(status_flags & ImGuiItemStatusFlags_HoveredRect))
IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
// Test if we are hovering the right window (our window could be behind another window)
// [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
// [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
// 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
// the test that has been running for a long while.
if (g.HoveredWindow != window && (status_flags & ImGuiItemStatusFlags_HoveredWindow) == 0)
if ((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0)
return false; return false;
IM_ASSERT((flags & (ImGuiHoveredFlags_AnyWindow | ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows | ImGuiHoveredFlags_NoPopupHierarchy)) == 0); // Flags not supported by this function
// Test if we are hovering the right window (our window could be behind another window)
// [2021/03/02] Reworked / reverted the revert, finally. Note we want e.g. BeginGroup/ItemAdd/EndGroup to work as well. (#3851)
// [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
// 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
// the test that has been running for a long while.
if (g.HoveredWindow != window && (status_flags & ImGuiItemStatusFlags_HoveredWindow) == 0)
if ((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0)
return false;
// Test if another item is active (e.g. being dragged)
if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0)
if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId)
return false;
// Test if another item is active (e.g. being dragged) // Test if interactions on this window are blocked by an active popup or modal.
if ((flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem) == 0) // The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here.
if (g.ActiveId != 0 && g.ActiveId != g.LastItemData.ID && !g.ActiveIdAllowOverlap && g.ActiveId != window->MoveId) if (!IsWindowContentHoverable(window, flags))
return false; return false;
// Test if interactions on this window are blocked by an active popup or modal. // Test if the item is disabled
// The ImGuiHoveredFlags_AllowWhenBlockedByPopup flag will be tested here. if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled))
if (!IsWindowContentHoverable(window, flags)) return false;
return false;
// Test if the item is disabled // Special handling for calling after Begin() which represent the title bar or tab.
if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled)) // When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
return false; if (g.LastItemData.ID == window->MoveId && window->WriteAccessed)
return false;
}
// Special handling for calling after Begin() which represent the title bar or tab.
// When the window is collapsed (SkipItems==true) that last item will never be overwritten so we need to detect the case.
if (g.LastItemData.ID == window->MoveId && window->WriteAccessed)
return false;
return true; return true;
} }

Loading…
Cancel
Save