Skip to content

Commit 695ea45

Browse files
committed
IsWindowHovered(): Changed default behavior to now return false is a widget from another window is active + Added support for ImGuiHoveredFlags_AllowWhenBlockedByActiveItem. (relate to drag'n drop idoms: #143)
1 parent 564ff2d commit 695ea45

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

imgui.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -5091,9 +5091,16 @@ const char* ImGui::GetStyleColorName(ImGuiCol idx)
50915091

50925092
bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
50935093
{
5094-
IM_ASSERT((flags & (ImGuiHoveredFlags_AllowWhenOverlapped | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) == 0); // Flags not supported by this function
5094+
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
50955095
ImGuiContext& g = *GImGui;
5096-
return g.HoveredWindow == g.CurrentWindow && IsWindowContentHoverable(g.HoveredRootWindow, flags);
5096+
if (g.HoveredWindow != g.CurrentWindow)
5097+
return false;
5098+
if (!IsWindowContentHoverable(g.HoveredRootWindow, flags))
5099+
return false;
5100+
if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
5101+
if (g.ActiveId != 0 && g.ActiveIdWindow != g.CurrentWindow)
5102+
return false;
5103+
return true;
50975104
}
50985105

50995106
bool ImGui::IsWindowFocused()
@@ -5116,9 +5123,16 @@ bool ImGui::IsRootWindowOrAnyChildFocused()
51165123

51175124
bool ImGui::IsRootWindowOrAnyChildHovered(ImGuiHoveredFlags flags)
51185125
{
5119-
IM_ASSERT((flags & (ImGuiHoveredFlags_AllowWhenOverlapped | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem)) == 0); // Flags not supported by this function
5126+
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
51205127
ImGuiContext& g = *GImGui;
5121-
return g.HoveredRootWindow && (g.HoveredRootWindow == g.CurrentWindow->RootWindow) && IsWindowContentHoverable(g.HoveredRootWindow, flags);
5128+
if (!g.HoveredRootWindow || (g.HoveredRootWindow != g.CurrentWindow->RootWindow))
5129+
return false;
5130+
if (!IsWindowContentHoverable(g.HoveredRootWindow, flags))
5131+
return false;
5132+
if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
5133+
if (g.ActiveId != 0 && g.ActiveIdWindow != g.CurrentWindow)
5134+
return false;
5135+
return true;
51225136
}
51235137

51245138
float ImGui::GetWindowWidth()

imgui_demo.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1768,11 +1768,11 @@ void ImGui::ShowTestWindow(bool* p_open)
17681768
// Testing IsWindowHovered() function
17691769
ImGui::BulletText(
17701770
"IsWindowHovered() = %d\n"
1771-
"IsWindowHovered(_AllowWhenBlockedByPopup) = %d\n",
1772-
//"IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d\n",
1771+
"IsWindowHovered(_AllowWhenBlockedByPopup) = %d\n"
1772+
"IsWindowHovered(_AllowWhenBlockedByActiveItem) = %d\n",
17731773
ImGui::IsWindowHovered(),
1774-
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup));
1775-
//ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem));
1774+
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup),
1775+
ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem));
17761776

17771777
// Testing IsItemHovered() function (because BulletText is an item itself and that would affect the output of IsItemHovered, we pass all lines in a single items to shorten the code)
17781778
ImGui::Button("ITEM");

0 commit comments

Comments
 (0)