mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 09:44:29 +00:00 
			
		
		
		
	Fix OuterRectClipped not being clipped correctly, which resulted in child window outside visible bound to not be marked with SkipItems. Broken in b50c61c961.
				
					
				
			+ Comments on InnerClipRect being misleading. Demo: Tweak to sizing of child window in the Layout->Scrolling section.
This commit is contained in:
		
							
								
								
									
										19
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -5463,10 +5463,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
 | 
			
		||||
        window->ContentsRegionRect.Max.x = window->Pos.x - window->Scroll.x - window->WindowPadding.x + (window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : (window->Size.x - window->ScrollbarSizes.x + ImMin(window->ScrollbarSizes.x, window->WindowBorderSize)));
 | 
			
		||||
        window->ContentsRegionRect.Max.y = window->Pos.y - window->Scroll.y - window->WindowPadding.y + (window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : (window->Size.y - window->ScrollbarSizes.y + ImMin(window->ScrollbarSizes.y, window->WindowBorderSize)));
 | 
			
		||||
 | 
			
		||||
        // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
 | 
			
		||||
        window->OuterRectClipped = window->Rect();
 | 
			
		||||
        window->OuterRectClipped.ClipWith(window->ClipRect);
 | 
			
		||||
 | 
			
		||||
        // Inner rectangle
 | 
			
		||||
        // We set this up after processing the resize grip so that our clip rectangle doesn't lag by a frame
 | 
			
		||||
        // Note that if our window is collapsed we will end up with an inverted (~null) clipping rectangle which is the correct behavior.
 | 
			
		||||
@@ -5476,13 +5472,23 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
 | 
			
		||||
        window->InnerMainRect.Max.x = window->Pos.x + window->Size.x - ImMax(window->ScrollbarSizes.x, window->WindowBorderSize);
 | 
			
		||||
        window->InnerMainRect.Max.y = window->Pos.y + window->Size.y - ImMax(window->ScrollbarSizes.y, window->WindowBorderSize);
 | 
			
		||||
 | 
			
		||||
        // Outer host rectangle for drawing background and borders
 | 
			
		||||
        ImRect host_rect = ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip) ? parent_window->ClipRect : viewport_rect;
 | 
			
		||||
 | 
			
		||||
        // Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
 | 
			
		||||
        window->OuterRectClipped = window->Rect();
 | 
			
		||||
        window->OuterRectClipped.ClipWith(host_rect);
 | 
			
		||||
 | 
			
		||||
        // Inner clipping rectangle will extend a little bit outside the work region.
 | 
			
		||||
        // This is to allow e.g. Selectable or CollapsingHeader or some separators to cover that space.
 | 
			
		||||
        // Force round operator last to ensure that e.g. (int)(max.x-min.x) in user's render code produce correct result.
 | 
			
		||||
        // FIXME: This is currently not clipped by the host rectangle, which is misleading because our call to PushClipRect() below will do it anyway.
 | 
			
		||||
        // If we fix the value in InnerClipRect, which is desirable, we need to fix the two lines of code relying on it.
 | 
			
		||||
        window->InnerClipRect.Min.x = ImFloor(0.5f + window->InnerMainRect.Min.x + ImMax(0.0f, ImFloor(window->WindowPadding.x * 0.5f - window->WindowBorderSize)));
 | 
			
		||||
        window->InnerClipRect.Min.y = ImFloor(0.5f + window->InnerMainRect.Min.y);
 | 
			
		||||
        window->InnerClipRect.Max.x = ImFloor(0.5f + window->InnerMainRect.Max.x - ImMax(0.0f, ImFloor(window->WindowPadding.x * 0.5f - window->WindowBorderSize)));
 | 
			
		||||
        window->InnerClipRect.Max.y = ImFloor(0.5f + window->InnerMainRect.Max.y);
 | 
			
		||||
        //window->InnerClipRect.ClipWithFull(host_rect);
 | 
			
		||||
 | 
			
		||||
        // DRAWING
 | 
			
		||||
 | 
			
		||||
@@ -5490,10 +5496,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
 | 
			
		||||
        window->DrawList->Clear();
 | 
			
		||||
        window->DrawList->Flags = (g.Style.AntiAliasedLines ? ImDrawListFlags_AntiAliasedLines : 0) | (g.Style.AntiAliasedFill ? ImDrawListFlags_AntiAliasedFill : 0);
 | 
			
		||||
        window->DrawList->PushTextureID(g.Font->ContainerAtlas->TexID);
 | 
			
		||||
        if ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip)
 | 
			
		||||
            PushClipRect(parent_window->ClipRect.Min, parent_window->ClipRect.Max, true);
 | 
			
		||||
        else
 | 
			
		||||
            PushClipRect(viewport_rect.Min, viewport_rect.Max, true);
 | 
			
		||||
        PushClipRect(host_rect.Min, host_rect.Max, false);
 | 
			
		||||
 | 
			
		||||
        // Draw modal window background (darkens what is behind them, all viewports)
 | 
			
		||||
        const bool dim_bg_for_modal = (flags & ImGuiWindowFlags_Modal) && window == GetFrontMostPopupModal() && window->HiddenFramesCannotSkipItems <= 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -2056,14 +2056,17 @@ static void ShowDemoWindowLayout()
 | 
			
		||||
        bool scroll_to = ImGui::Button("Scroll To Pos");
 | 
			
		||||
        ImGui::SameLine(130); scroll_to |= ImGui::DragInt("##pos_y", &scroll_to_px, 1.00f, 0, 9999, "Y = %d px");
 | 
			
		||||
        ImGui::PopItemWidth();
 | 
			
		||||
        if (scroll_to) track = false;
 | 
			
		||||
        if (scroll_to) 
 | 
			
		||||
            track = false;
 | 
			
		||||
 | 
			
		||||
        ImGuiStyle& style = ImGui::GetStyle();
 | 
			
		||||
        float child_w = (ImGui::GetContentRegionAvail().x - 4 * style.ItemSpacing.x) / 5;
 | 
			
		||||
        for (int i = 0; i < 5; i++)
 | 
			
		||||
        {
 | 
			
		||||
            if (i > 0) ImGui::SameLine();
 | 
			
		||||
            ImGui::BeginGroup();
 | 
			
		||||
            ImGui::Text("%s", i == 0 ? "Top" : i == 1 ? "25%" : i == 2 ? "Center" : i == 3 ? "75%" : "Bottom");
 | 
			
		||||
            ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(ImGui::GetWindowWidth() * 0.17f, 200.0f), true);
 | 
			
		||||
            ImGui::BeginChild(ImGui::GetID((void*)(intptr_t)i), ImVec2(child_w, 200.0f), true);
 | 
			
		||||
            if (scroll_to)
 | 
			
		||||
                ImGui::SetScrollFromPosY(ImGui::GetCursorStartPos().y + scroll_to_px, i * 0.25f);
 | 
			
		||||
            for (int line = 0; line < 100; line++)
 | 
			
		||||
@@ -2078,7 +2081,8 @@ static void ShowDemoWindowLayout()
 | 
			
		||||
                    ImGui::Text("Line %d", line);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            float scroll_y = ImGui::GetScrollY(), scroll_max_y = ImGui::GetScrollMaxY();
 | 
			
		||||
            float scroll_y = ImGui::GetScrollY();
 | 
			
		||||
            float scroll_max_y = ImGui::GetScrollMaxY();
 | 
			
		||||
            ImGui::EndChild();
 | 
			
		||||
            ImGui::Text("%.0f/%0.f", scroll_y, scroll_max_y);
 | 
			
		||||
            ImGui::EndGroup();
 | 
			
		||||
 
 | 
			
		||||
@@ -1290,8 +1290,9 @@ struct IMGUI_API ImGuiWindow
 | 
			
		||||
    ImGuiWindowTempData     DC;                                 // Temporary per-window data, reset at the beginning of the frame. This used to be called ImGuiDrawContext, hence the "DC" variable name.
 | 
			
		||||
    ImVector<ImGuiID>       IDStack;                            // ID stack. ID are hashes seeded with the value at the top of the stack
 | 
			
		||||
    ImRect                  ClipRect;                           // Current clipping rectangle. = DrawList->clip_rect_stack.back(). Scissoring / clipping rectangle. x1, y1, x2, y2.
 | 
			
		||||
    ImRect                  OuterRectClipped;                   // = WindowRect just after setup in Begin(). == window->Rect() for root window.
 | 
			
		||||
    ImRect                  InnerMainRect, InnerClipRect;
 | 
			
		||||
    ImRect                  OuterRectClipped;                   // == WindowRect just after setup in Begin(). == window->Rect() for root window.
 | 
			
		||||
    ImRect                  InnerMainRect;                      //
 | 
			
		||||
    ImRect                  InnerClipRect;                      // == InnerMainRect, minus WindowPadding on each side, clipped within viewport or parent.
 | 
			
		||||
    ImRect                  ContentsRegionRect;                 // FIXME: This is currently confusing/misleading. Maximum visible content position ~~ Pos + (SizeContentsExplicit ? SizeContentsExplicit : Size - ScrollbarSizes) - CursorStartPos, per axis
 | 
			
		||||
    int                     LastFrameActive;                    // Last frame number the window was Active.
 | 
			
		||||
    float                   ItemWidthDefault;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user