mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internals: refactored IsWindowHovered()/IsWindowFocused() to make their logic more similar + change underlying value of ImGuiHoveredFlags_AllowWhenBlockedByPopup + comment out docking only flags.
This commit is contained in:
parent
d9b427cce0
commit
321b84f01f
66
imgui.cpp
66
imgui.cpp
@ -6740,37 +6740,31 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
|
|||||||
{
|
{
|
||||||
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
|
IM_ASSERT((flags & ImGuiHoveredFlags_AllowWhenOverlapped) == 0); // Flags not supported by this function
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
if (g.HoveredWindow == NULL)
|
ImGuiWindow* ref_window = g.HoveredWindow;
|
||||||
|
ImGuiWindow* cur_window = g.CurrentWindow;
|
||||||
|
if (ref_window == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ((flags & ImGuiHoveredFlags_AnyWindow) == 0)
|
if ((flags & ImGuiHoveredFlags_AnyWindow) == 0)
|
||||||
{
|
{
|
||||||
ImGuiWindow* window = g.CurrentWindow;
|
IM_ASSERT(cur_window); // Not inside a Begin()/End()
|
||||||
switch (flags & (ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows))
|
|
||||||
{
|
if (flags & ImGuiHoveredFlags_RootWindow)
|
||||||
case ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows:
|
cur_window = cur_window->RootWindow;
|
||||||
if (g.HoveredWindow->RootWindow != window->RootWindow)
|
|
||||||
return false;
|
bool result;
|
||||||
break;
|
if (flags & ImGuiHoveredFlags_ChildWindows)
|
||||||
case ImGuiHoveredFlags_RootWindow:
|
result = IsWindowChildOf(ref_window, cur_window);
|
||||||
if (g.HoveredWindow != window->RootWindow)
|
else
|
||||||
return false;
|
result = (ref_window == cur_window);
|
||||||
break;
|
if (!result)
|
||||||
case ImGuiHoveredFlags_ChildWindows:
|
return false;
|
||||||
if (!IsWindowChildOf(g.HoveredWindow, window))
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (g.HoveredWindow != window)
|
|
||||||
return false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!IsWindowContentHoverable(g.HoveredWindow, flags))
|
if (!IsWindowContentHoverable(ref_window, flags))
|
||||||
return false;
|
return false;
|
||||||
if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
|
if (!(flags & ImGuiHoveredFlags_AllowWhenBlockedByActiveItem))
|
||||||
if (g.ActiveId != 0 && !g.ActiveIdAllowOverlap && g.ActiveId != g.HoveredWindow->MoveId)
|
if (g.ActiveId != 0 && !g.ActiveIdAllowOverlap && g.ActiveId != ref_window->MoveId)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -6778,22 +6772,22 @@ bool ImGui::IsWindowHovered(ImGuiHoveredFlags flags)
|
|||||||
bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags)
|
bool ImGui::IsWindowFocused(ImGuiFocusedFlags flags)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
ImGuiWindow* ref_window = g.NavWindow;
|
||||||
|
ImGuiWindow* cur_window = g.CurrentWindow;
|
||||||
|
|
||||||
|
if (ref_window == NULL)
|
||||||
|
return false;
|
||||||
if (flags & ImGuiFocusedFlags_AnyWindow)
|
if (flags & ImGuiFocusedFlags_AnyWindow)
|
||||||
return g.NavWindow != NULL;
|
return true;
|
||||||
|
IM_ASSERT(cur_window); // Not inside a Begin()/End()
|
||||||
|
|
||||||
IM_ASSERT(g.CurrentWindow); // Not inside a Begin()/End()
|
if (flags & ImGuiHoveredFlags_RootWindow)
|
||||||
switch (flags & (ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows))
|
cur_window = cur_window->RootWindow;
|
||||||
{
|
|
||||||
case ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows:
|
if (flags & ImGuiHoveredFlags_ChildWindows)
|
||||||
return g.NavWindow && g.NavWindow->RootWindow == g.CurrentWindow->RootWindow;
|
return IsWindowChildOf(ref_window, cur_window);
|
||||||
case ImGuiFocusedFlags_RootWindow:
|
else
|
||||||
return g.NavWindow == g.CurrentWindow->RootWindow;
|
return (ref_window == cur_window);
|
||||||
case ImGuiFocusedFlags_ChildWindows:
|
|
||||||
return g.NavWindow && IsWindowChildOf(g.NavWindow, g.CurrentWindow);
|
|
||||||
default:
|
|
||||||
return g.NavWindow == g.CurrentWindow;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext)
|
// Can we focus this window with CTRL+TAB (or PadMenu + PadFocusPrev/PadFocusNext)
|
||||||
|
10
imgui.h
10
imgui.h
@ -1264,9 +1264,10 @@ enum ImGuiTableBgTarget_
|
|||||||
enum ImGuiFocusedFlags_
|
enum ImGuiFocusedFlags_
|
||||||
{
|
{
|
||||||
ImGuiFocusedFlags_None = 0,
|
ImGuiFocusedFlags_None = 0,
|
||||||
ImGuiFocusedFlags_ChildWindows = 1 << 0, // IsWindowFocused(): Return true if any children of the window is focused
|
ImGuiFocusedFlags_ChildWindows = 1 << 0, // Return true if any children of the window is focused
|
||||||
ImGuiFocusedFlags_RootWindow = 1 << 1, // IsWindowFocused(): Test from root window (top most parent of the current hierarchy)
|
ImGuiFocusedFlags_RootWindow = 1 << 1, // Test from root window (top most parent of the current hierarchy)
|
||||||
ImGuiFocusedFlags_AnyWindow = 1 << 2, // IsWindowFocused(): Return true if any window is focused. Important: If you are trying to tell how to dispatch your low-level inputs, do NOT use this. Use 'io.WantCaptureMouse' instead! Please read the FAQ!
|
ImGuiFocusedFlags_AnyWindow = 1 << 2, // Return true if any window is focused. Important: If you are trying to tell how to dispatch your low-level inputs, do NOT use this. Use 'io.WantCaptureMouse' instead! Please read the FAQ!
|
||||||
|
//ImGuiFocusedFlags_DockHierarchy = 1 << 3, // Consider docking hierarchy (treat dockspace host as parent of docked window)
|
||||||
ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows
|
ImGuiFocusedFlags_RootAndChildWindows = ImGuiFocusedFlags_RootWindow | ImGuiFocusedFlags_ChildWindows
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1279,7 +1280,8 @@ enum ImGuiHoveredFlags_
|
|||||||
ImGuiHoveredFlags_ChildWindows = 1 << 0, // IsWindowHovered() only: Return true if any children of the window is hovered
|
ImGuiHoveredFlags_ChildWindows = 1 << 0, // IsWindowHovered() only: Return true if any children of the window is hovered
|
||||||
ImGuiHoveredFlags_RootWindow = 1 << 1, // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy)
|
ImGuiHoveredFlags_RootWindow = 1 << 1, // IsWindowHovered() only: Test from root window (top most parent of the current hierarchy)
|
||||||
ImGuiHoveredFlags_AnyWindow = 1 << 2, // IsWindowHovered() only: Return true if any window is hovered
|
ImGuiHoveredFlags_AnyWindow = 1 << 2, // IsWindowHovered() only: Return true if any window is hovered
|
||||||
ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 3, // Return true even if a popup window is normally blocking access to this item/window
|
//ImGuiHoveredFlags_DockHierarchy = 1 << 3, // IsWindowHovered() only: Consider docking hierarchy (treat dockspace host as parent of docked window)
|
||||||
|
ImGuiHoveredFlags_AllowWhenBlockedByPopup = 1 << 4, // Return true even if a popup window is normally blocking access to this item/window
|
||||||
//ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 4, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
|
//ImGuiHoveredFlags_AllowWhenBlockedByModal = 1 << 4, // Return true even if a modal popup window is normally blocking access to this item/window. FIXME-TODO: Unavailable yet.
|
||||||
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 5, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
|
ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 5, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns.
|
||||||
ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 6, // Return true even if the position is obstructed or overlapped by another window
|
ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 6, // Return true even if the position is obstructed or overlapped by another window
|
||||||
|
Loading…
Reference in New Issue
Block a user