From a8bdbfddf95ee1a16e89677e3fd29fe93863242c Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 16 Oct 2023 21:41:36 +0200 Subject: [PATCH] Tables: Fixed top-most and left-most outer border overlapping inner clip-rect when scrolling. (#6765) --- docs/CHANGELOG.txt | 1 + imgui_tables.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2f8ef3d0..17bfd97e 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -107,6 +107,7 @@ Other changes: so a scrolling table can contribute to initial window size. (#6510) - Fixed subtle drawing overlap between borders in some situations. - Fixed bottom-most and right-most outer border offset by one. (#6765, #3752) [@v-ein] + - Fixed top-most and left-most outer border overlapping inner clip-rect when scrolling. (#6765) - Fixed top-most outer border being drawn with both TableBorderLight and TableBorderStrong in some situations, causing the earlier to be visible underneath when alpha is not 1.0f. - Fixed right-clicking right-most section (past right-most column) from highlighting a column. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index fac9b05f..3d8d3cff 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -445,6 +445,18 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG temp_data->HostBackupItemWidthStackSize = outer_window->DC.ItemWidthStack.Size; inner_window->DC.PrevLineSize = inner_window->DC.CurrLineSize = ImVec2(0.0f, 0.0f); + // Make left and top borders not overlap our contents by offsetting HostClipRect (#6765) + // (we normally shouldn't alter HostClipRect as we rely on TableMergeDrawChannels() expanding non-clipped column toward the + // limits of that rectangle, in order for ImDrawListSplitter::Merge() to merge the draw commands. However since the overlap + // problem only affect scrolling tables in this case we can get away with doing it without extra cost). + if (inner_window != outer_window) + { + if (flags & ImGuiTableFlags_BordersOuterV) + table->HostClipRect.Min.x = ImMin(table->HostClipRect.Min.x + TABLE_BORDER_SIZE, table->HostClipRect.Max.x); + if (flags & ImGuiTableFlags_BordersOuterH) + table->HostClipRect.Min.y = ImMin(table->HostClipRect.Min.y + TABLE_BORDER_SIZE, table->HostClipRect.Max.y); + } + // Padding and Spacing // - None ........Content..... Pad .....Content........ // - PadOuter | Pad ..Content..... Pad .....Content.. Pad | @@ -1149,7 +1161,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table) table->InnerClipRect.Max.x = ImMin(table->InnerClipRect.Max.x, unused_x1); } table->InnerWindow->ParentWorkRect = table->WorkRect; - table->BorderX1 = table->InnerClipRect.Min.x + ((table->Flags & ImGuiTableFlags_BordersOuterV) ? 1.0f : 0.0f); + table->BorderX1 = table->InnerClipRect.Min.x; table->BorderX2 = table->InnerClipRect.Max.x; // Setup window's WorkRect.Max.y for GetContentRegionAvail(). Other values will be updated in each TableBeginCell() call.