mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	Window rectangles: Changed WorkRect to cover the whole region including scrolling (toward obsolete ContentsRegionRect) + using full WindowPadding*1 padding.
Tweaked InnerClipRect. TreeNode, CollapsingHeader: Fixed highlight frame not covering horizontal area fully when using horizontal scrolling. (#2211, #2579) TabBar: Fixed BeginTabBar() within a window with horizontal scrolling from creating a feedback loop with the horizontal contents size. Columns: Fixed Columns() within a window with horizontal scrolling from not covering the full horizontal area (previously only worked with an explicit contents size). (#125) Demo: Added demo code to test contentsrect/workrect
This commit is contained in:
		
							
								
								
									
										44
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								imgui.cpp
									
									
									
									
									
								
							| @@ -4999,8 +4999,6 @@ static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window) | ||||
|     } | ||||
| } | ||||
|  | ||||
| // Draw background and borders | ||||
| // Draw and handle scrollbars | ||||
| void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size) | ||||
| { | ||||
|     ImGuiContext& g = *GImGui; | ||||
| @@ -5511,7 +5509,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) | ||||
|         // - Begin() initial clipping rect for drawing window background and borders. | ||||
|         // - Begin() clipping whole child | ||||
|         ImRect host_rect = ((flags & ImGuiWindowFlags_ChildWindow) && !(flags & ImGuiWindowFlags_Popup) && !window_is_child_tooltip) ? parent_window->ClipRect : viewport_rect; | ||||
|         window->OuterRectClipped = window->Rect(); | ||||
|         ImRect outer_rect = window->Rect(); | ||||
|         window->OuterRectClipped = outer_rect; | ||||
|         window->OuterRectClipped.ClipWith(host_rect); | ||||
|  | ||||
|         // Inner rectangle | ||||
| @@ -5525,15 +5524,6 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) | ||||
|         window->InnerRect.Max.x = window->Pos.x + window->Size.x - window->ScrollbarSizes.x; | ||||
|         window->InnerRect.Max.y = window->Pos.y + window->Size.y - window->ScrollbarSizes.y; | ||||
|  | ||||
|         // Work rectangle. | ||||
|         // Affected by window padding and border size. Used by: | ||||
|         // - Columns() for right-most edge | ||||
|         // - BeginTabBar() for right-most edge | ||||
|         window->WorkRect.Min.x = ImFloor(0.5f + window->InnerRect.Min.x + ImMax(0.0f, ImFloor(window->WindowPadding.x * 0.5f - window->WindowBorderSize))); | ||||
|         window->WorkRect.Min.y = ImFloor(0.5f + window->InnerRect.Min.y); | ||||
|         window->WorkRect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(0.0f, ImFloor(window->WindowPadding.x * 0.5f - window->WindowBorderSize))); | ||||
|         window->WorkRect.Max.y = ImFloor(0.5f + window->InnerRect.Max.y); | ||||
|  | ||||
|         // Inner clipping rectangle. | ||||
|         // Will extend a little bit outside the normal work region. | ||||
|         // This is to allow e.g. Selectable or CollapsingHeader or some separators to cover that space. | ||||
| @@ -5541,7 +5531,11 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) | ||||
|         // Note that if our window is collapsed we will end up with an inverted (~null) clipping rectangle which is the correct behavior. | ||||
|         // Affected by window/frame border size. Used by: | ||||
|         // - Begin() initial clip rect | ||||
|         window->InnerClipRect = window->WorkRect; | ||||
|         float top_border_size = (((flags & ImGuiWindowFlags_MenuBar) || !(flags & ImGuiWindowFlags_NoTitleBar)) ? style.FrameBorderSize : window->WindowBorderSize); | ||||
|         window->InnerClipRect.Min.x = ImFloor(0.5f + window->InnerRect.Min.x + ImMax(ImFloor(window->WindowPadding.x * 0.5f), window->WindowBorderSize)); | ||||
|         window->InnerClipRect.Min.y = ImFloor(0.5f + window->InnerRect.Min.y + top_border_size); | ||||
|         window->InnerClipRect.Max.x = ImFloor(0.5f + window->InnerRect.Max.x - ImMax(ImFloor(window->WindowPadding.y * 0.5f), window->WindowBorderSize)); | ||||
|         window->InnerClipRect.Max.y = ImFloor(0.5f + window->InnerRect.Max.y - window->WindowBorderSize); | ||||
|         window->InnerClipRect.ClipWithFull(host_rect); | ||||
|  | ||||
|         // DRAWING | ||||
| @@ -5589,12 +5583,25 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) | ||||
|  | ||||
|         // UPDATE RECTANGLES (2- THOSE AFFECTED BY SCROLLING) | ||||
|  | ||||
|         // Work rectangle. | ||||
|         // Affected by window padding and border size. Used by: | ||||
|         // - Columns() for right-most edge | ||||
|         // - TreeNode(), CollapsingHeader() for right-most edge | ||||
|         // - BeginTabBar() for right-most edge | ||||
|         const bool allow_scrollbar_x = !(flags & ImGuiWindowFlags_NoScrollbar) && (flags & ImGuiWindowFlags_HorizontalScrollbar); | ||||
|         const bool allow_scrollbar_y = !(flags & ImGuiWindowFlags_NoScrollbar); | ||||
|         const float work_rect_size_x = (window->SizeContentsExplicit.x != 0.0f ? window->SizeContentsExplicit.x : ImMax(allow_scrollbar_x ? window->SizeContents.x : 0.0f, window->InnerRect.GetWidth() - window->WindowPadding.x * 2.0f)); | ||||
|         const float work_rect_size_y = (window->SizeContentsExplicit.y != 0.0f ? window->SizeContentsExplicit.y : ImMax(allow_scrollbar_y ? window->SizeContents.y : 0.0f, window->InnerRect.GetHeight() - window->WindowPadding.y * 2.0f)); | ||||
|         window->WorkRect.Min.x = ImFloor(window->InnerRect.Min.x - window->Scroll.x + ImMax(window->WindowPadding.x, window->WindowBorderSize)); | ||||
|         window->WorkRect.Min.y = ImFloor(window->InnerRect.Min.y - window->Scroll.y + ImMax(window->WindowPadding.y, window->WindowBorderSize)); | ||||
|         window->WorkRect.Max.x = window->WorkRect.Min.x + work_rect_size_x; | ||||
|         window->WorkRect.Max.y = window->WorkRect.Min.y + work_rect_size_y; | ||||
|  | ||||
|         // [LEGACY] Contents Region | ||||
|         // FIXME: window->ContentsRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it. | ||||
|         // FIXME-OBSOLETE: window->ContentsRegionRect.Max is currently very misleading / partly faulty, but some BeginChild() patterns relies on it. | ||||
|         // NB: WindowBorderSize is included in WindowPadding _and_ ScrollbarSizes so we need to cancel one out when we have both. | ||||
|         // Used by: | ||||
|         // - Mouse wheel scrolling | ||||
|         // - ... (many things) | ||||
|         // - Mouse wheel scrolling + many other things | ||||
|         window->ContentsRegionRect.Min.x = window->Pos.x - window->Scroll.x + window->WindowPadding.x; | ||||
|         window->ContentsRegionRect.Min.y = window->Pos.y - window->Scroll.y + window->WindowPadding.y + window->TitleBarHeight() + window->MenuBarHeight(); | ||||
|         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))); | ||||
| @@ -8719,9 +8726,8 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag | ||||
|     window->DC.CurrentColumns = columns; | ||||
|  | ||||
|     // Set state for first column | ||||
|     const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->WorkRect.Max.x - window->Pos.x); | ||||
|     columns->OffMinX = window->DC.Indent.x - g.Style.ItemSpacing.x; // Lock our horizontal range | ||||
|     columns->OffMaxX = ImMax(content_region_width - window->Scroll.x, columns->OffMinX + 1.0f); | ||||
|     columns->OffMinX = window->DC.Indent.x - g.Style.ItemSpacing.x; | ||||
|     columns->OffMaxX = ImMax(window->WorkRect.Max.x - window->Pos.x, columns->OffMinX + 1.0f); | ||||
|     columns->HostCursorPosY = window->DC.CursorPos.y; | ||||
|     columns->HostCursorMaxPosX = window->DC.CursorMaxPos.x; | ||||
|     columns->HostClipRect = window->ClipRect; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user