diff --git a/imgui.cpp b/imgui.cpp index c9b7031..747fcba 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1951,7 +1951,6 @@ // This is roughly matching the behavior of internal-facing IsHovered() // - 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()) -// - we don't expose the flatten_child feature that IsHovered() has, which is only used by the window resizing widget (may rework this) bool ImGui::IsItemHovered() { ImGuiContext& g = *GImGui; @@ -1972,13 +1971,13 @@ } // Internal facing IsHovered() differs slightly from IsItemHovered(). -bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs) +bool ImGui::IsHovered(const ImRect& bb, ImGuiID id) { ImGuiContext& g = *GImGui; if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap) { ImGuiWindow* window = g.CurrentWindow; - if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow)) + if (g.HoveredWindow == window) if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) if (IsMouseHoveringRect(bb.Min, bb.Max)) if (IsWindowContentHoverable(g.HoveredRootWindow)) @@ -4274,6 +4273,7 @@ if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && !(flags & ImGuiWindowFlags_NoResize)) { // Manual resize + // Using the FlattenChilds button flag, we make the resize button accessible even if we are hovering over a child window const ImVec2 br = window->Rect().GetBR(); const ImRect resize_rect(br - ImVec2(resize_corner_size * 0.75f, resize_corner_size * 0.75f), br); const ImGuiID resize_id = window->GetID("#RESIZE"); @@ -5673,8 +5673,16 @@ if ((flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick)) == 0) flags |= ImGuiButtonFlags_PressedOnClickRelease; + ImGuiWindow* backup_hovered_window = g.HoveredWindow; + if ((flags & ImGuiButtonFlags_FlattenChilds) && g.HoveredRootWindow == window) + g.HoveredWindow = window; + bool pressed = false; - bool hovered = IsHovered(bb, id, (flags & ImGuiButtonFlags_FlattenChilds) != 0); + bool hovered = IsHovered(bb, id); + + if ((flags & ImGuiButtonFlags_FlattenChilds) && g.HoveredRootWindow == window) + g.HoveredWindow = backup_hovered_window; + if (hovered) { SetHoveredID(id); diff --git a/imgui.cpp b/imgui.cpp index c9b7031..747fcba 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1951,7 +1951,6 @@ // This is roughly matching the behavior of internal-facing IsHovered() // - 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()) -// - we don't expose the flatten_child feature that IsHovered() has, which is only used by the window resizing widget (may rework this) bool ImGui::IsItemHovered() { ImGuiContext& g = *GImGui; @@ -1972,13 +1971,13 @@ } // Internal facing IsHovered() differs slightly from IsItemHovered(). -bool ImGui::IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs) +bool ImGui::IsHovered(const ImRect& bb, ImGuiID id) { ImGuiContext& g = *GImGui; if (g.HoveredId == 0 || g.HoveredId == id || g.HoveredIdAllowOverlap) { ImGuiWindow* window = g.CurrentWindow; - if (g.HoveredWindow == window || (flatten_childs && g.HoveredRootWindow == window->RootWindow)) + if (g.HoveredWindow == window) if (g.ActiveId == 0 || g.ActiveId == id || g.ActiveIdAllowOverlap) if (IsMouseHoveringRect(bb.Min, bb.Max)) if (IsWindowContentHoverable(g.HoveredRootWindow)) @@ -4274,6 +4273,7 @@ if (!(flags & ImGuiWindowFlags_AlwaysAutoResize) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0 && !(flags & ImGuiWindowFlags_NoResize)) { // Manual resize + // Using the FlattenChilds button flag, we make the resize button accessible even if we are hovering over a child window const ImVec2 br = window->Rect().GetBR(); const ImRect resize_rect(br - ImVec2(resize_corner_size * 0.75f, resize_corner_size * 0.75f), br); const ImGuiID resize_id = window->GetID("#RESIZE"); @@ -5673,8 +5673,16 @@ if ((flags & (ImGuiButtonFlags_PressedOnClickRelease | ImGuiButtonFlags_PressedOnClick | ImGuiButtonFlags_PressedOnRelease | ImGuiButtonFlags_PressedOnDoubleClick)) == 0) flags |= ImGuiButtonFlags_PressedOnClickRelease; + ImGuiWindow* backup_hovered_window = g.HoveredWindow; + if ((flags & ImGuiButtonFlags_FlattenChilds) && g.HoveredRootWindow == window) + g.HoveredWindow = window; + bool pressed = false; - bool hovered = IsHovered(bb, id, (flags & ImGuiButtonFlags_FlattenChilds) != 0); + bool hovered = IsHovered(bb, id); + + if ((flags & ImGuiButtonFlags_FlattenChilds) && g.HoveredRootWindow == window) + g.HoveredWindow = backup_hovered_window; + if (hovered) { SetHoveredID(id); diff --git a/imgui_internal.h b/imgui_internal.h index a1192be..9329e46 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -771,7 +771,7 @@ IMGUI_API void ItemSize(const ImRect& bb, float text_offset_y = 0.0f); IMGUI_API bool ItemAdd(const ImRect& bb, const ImGuiID* id); IMGUI_API bool IsClippedEx(const ImRect& bb, const ImGuiID* id, bool clip_even_when_logged); - IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id, bool flatten_childs = false); + IMGUI_API bool IsHovered(const ImRect& bb, ImGuiID id); IMGUI_API bool FocusableItemRegister(ImGuiWindow* window, ImGuiID id, bool tab_stop = true); // Return true if focus is requested IMGUI_API void FocusableItemUnregister(ImGuiWindow* window); IMGUI_API ImVec2 CalcItemSize(ImVec2 size, float default_x, float default_y);