From 4229b7e60b06a54715b4829560d9b2c0db22a314 Mon Sep 17 00:00:00 2001 From: ocornut Date: Sun, 22 Feb 2015 12:05:38 +0000 Subject: [PATCH] Fix hovering of child window extending past their parent not taking account of parent clipping rectangle (Fix #137) --- imgui.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 785c4508..810f4a77 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1103,6 +1103,7 @@ struct ImGuiWindow ImGuiDrawContext DC; ImVector IDStack; ImVector ClipRectStack; // Scissoring / clipping rectangle. x1, y1, x2, y2. + ImGuiAabb ClippedAabb; // = ClipRectStack.front() after setup in Begin() int LastFrameDrawn; float ItemWidthDefault; ImGuiStorage StateStorage; @@ -1416,8 +1417,7 @@ ImGuiWindow::ImGuiWindow(const char* name) { Name = ImStrdup(name); ID = GetID(name); - IDStack.push_back(ID); - + Flags = 0; PosFloat = Pos = ImVec2(0.0f, 0.0f); Size = SizeFull = ImVec2(0.0f, 0.0f); SizeContentsFit = ImVec2(0.0f, 0.0f); @@ -1432,6 +1432,7 @@ ImGuiWindow::ImGuiWindow(const char* name) AutoFitOnlyGrows = false; SetWindowPosAllowFlags = SetWindowSizeAllowFlags = SetWindowCollapsedAllowFlags = ImGuiSetCondition_Always | ImGuiSetCondition_FirstUseThisSession | ImGuiSetCondition_FirstUseEver; + IDStack.push_back(ID); LastFrameDrawn = -1; ItemWidthDefault = 0.0f; FontWindowScale = 1.0f; @@ -1444,6 +1445,7 @@ ImGuiWindow::ImGuiWindow(const char* name) DrawList = (ImDrawList*)ImGui::MemAlloc(sizeof(ImDrawList)); new(DrawList) ImDrawList(); + RootWindow = NULL; FocusIdxAllCounter = FocusIdxTabCounter = -1; FocusIdxAllRequestCurrent = FocusIdxTabRequestCurrent = IM_INT_MAX; @@ -2332,7 +2334,9 @@ static ImGuiWindow* FindHoveredWindow(ImVec2 pos, bool excluding_childs) continue; if (excluding_childs && (window->Flags & ImGuiWindowFlags_ChildWindow) != 0) continue; - ImGuiAabb bb(window->Pos - g.Style.TouchExtraPadding, window->Pos + window->Size + g.Style.TouchExtraPadding); + + // Using the clipped AABB so a child window will typically be clipped by its parent. + ImGuiAabb bb(window->ClippedAabb.Min - g.Style.TouchExtraPadding, window->ClippedAabb.Max + g.Style.TouchExtraPadding); if (bb.Contains(pos)) return window; } @@ -3046,6 +3050,10 @@ bool ImGui::Begin(const char* name, bool* p_opened, ImVec2 size, float fill_alph const ImVec2 text_max = window->Pos + ImVec2(window->Size.x - (p_opened ? (title_bar_aabb.GetHeight()-3) : style.FramePadding.x), style.FramePadding.y*2 + text_size.y); RenderTextClipped(text_min, name, NULL, &text_size, text_max); } + + // Save clipped aabb so we can access it in constant-time in FindHoveredWindow() + window->ClippedAabb = window->Aabb(); + window->ClippedAabb.Clip(window->ClipRectStack.front()); } // Inner clipping rectangle