Added IsRootWindowOrAnyChildHovered() helper (#615)

This commit is contained in:
ocornut 2016-05-01 12:14:07 +02:00
parent 60d6c6d0e8
commit befe02559a
2 changed files with 10 additions and 5 deletions

View File

@ -4579,15 +4579,19 @@ bool ImGui::IsWindowFocused()
bool ImGui::IsRootWindowFocused() bool ImGui::IsRootWindowFocused()
{ {
ImGuiState& g = *GImGui; ImGuiState& g = *GImGui;
ImGuiWindow* root_window = g.CurrentWindow->RootWindow; return g.FocusedWindow == g.CurrentWindow->RootWindow;
return g.FocusedWindow == root_window;
} }
bool ImGui::IsRootWindowOrAnyChildFocused() bool ImGui::IsRootWindowOrAnyChildFocused()
{ {
ImGuiState& g = *GImGui; ImGuiState& g = *GImGui;
ImGuiWindow* root_window = g.CurrentWindow->RootWindow; return g.FocusedWindow && g.FocusedWindow->RootWindow == g.CurrentWindow->RootWindow;
return g.FocusedWindow && g.FocusedWindow->RootWindow == root_window; }
bool ImGui::IsRootWindowOrAnyChildHovered()
{
ImGuiState& g = *GImGui;
return g.HoveredRootWindow && (g.HoveredRootWindow == g.CurrentWindow->RootWindow) && IsWindowContentHoverable(g.HoveredRootWindow);
} }
float ImGui::GetWindowWidth() float ImGui::GetWindowWidth()

View File

@ -385,8 +385,9 @@ namespace ImGui
IMGUI_API void SetItemAllowOverlap(); // allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area. IMGUI_API void SetItemAllowOverlap(); // allow last item to be overlapped by a subsequent item. sometimes useful with invisible buttons, selectables, etc. to catch unused area.
IMGUI_API bool IsWindowHovered(); // is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others) IMGUI_API bool IsWindowHovered(); // is current window hovered and hoverable (not blocked by a popup) (differentiate child windows from each others)
IMGUI_API bool IsWindowFocused(); // is current window focused IMGUI_API bool IsWindowFocused(); // is current window focused
IMGUI_API bool IsRootWindowFocused(); // is current root window focused (top parent window in case of child windows) IMGUI_API bool IsRootWindowFocused(); // is current root window focused (root = top-most parent of a child, otherwise self)
IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused IMGUI_API bool IsRootWindowOrAnyChildFocused(); // is current root window or any of its child (including current window) focused
IMGUI_API bool IsRootWindowOrAnyChildHovered(); // is current root window or any of its child (including current window) hovered and hoverable (not blocked by a popup)
IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization) IMGUI_API bool IsRectVisible(const ImVec2& size); // test if rectangle of given size starting from cursor pos is visible (not clipped). to perform coarse clipping on user's side (as an optimization)
IMGUI_API bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window IMGUI_API bool IsPosHoveringAnyWindow(const ImVec2& pos); // is given position hovering any active imgui window
IMGUI_API float GetTime(); IMGUI_API float GetTime();