From 4abc2a82e0f258288ec252d810a1ab772619a528 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 19 Jul 2019 13:28:40 -0700 Subject: [PATCH] Columns: Made the right-most edge reaches up to the clipping rectangle (removing WindowPadding.x*0.5 worth of asymmetrical/extraneous padding). (#125, #2666) + Moved a few things in BeginColumns(). --- docs/CHANGELOG.txt | 3 +++ imgui_widgets.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 10d36d08..3722438f 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -58,6 +58,9 @@ Other Changes: - TabBar: Fixed unfocused tab bar separator color (was using ImGuiCol_Tab, should use ImGuiCol_TabUnfocusedActive). - Columns: Fixed a regression from 1.71 where the right-side of the contents rectangle within each column would wrongly use a WindowPadding.x instead of ItemSpacing.x like it always did. (#125, #2666) +- Columns: Made the right-most edge reaches up to the clipping rectangle (removing half of WindowPadding.x + worth of asymmetrical/extraneous padding, note that there's another half that conservatively has to offset + the right-most column, otherwise it's clipping width won't match the other column). (#125, #2666) - Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d). - Scrolling: Added SetScrollHereX(), SetScrollFromPosX() for completeness. (#1580) [@kevreco] diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 0878b46c..3c2405ff 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -7304,13 +7304,13 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag columns->HostWorkRect = window->WorkRect; // Set state for first column + // We aim so that the right-most column will have the same clipping width as other after being clipped by parent ClipRect const float column_padding = g.Style.ItemSpacing.x; + const float half_clip_extend_x = ImFloor(ImMax(window->WindowPadding.x * 0.5f, window->WindowBorderSize)); columns->OffMinX = window->DC.Indent.x - column_padding; - columns->OffMaxX = window->WorkRect.Max.x - window->Pos.x; + columns->OffMaxX = window->WorkRect.Max.x + half_clip_extend_x - window->Pos.x; columns->OffMaxX = ImMax(columns->OffMaxX, columns->OffMinX + 1.0f); columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y; - window->DC.ColumnsOffset.x = 0.0f; - window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); // Clear data if columns count changed if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1) @@ -7346,10 +7346,13 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag PushColumnClipRect(0); } + // We don't generally store Indent.x inside ColumnsOffset because it may be manipulated by the user. float offset_0 = GetColumnOffset(columns->Current); float offset_1 = GetColumnOffset(columns->Current + 1); float width = offset_1 - offset_0; PushItemWidth(width * 0.65f); + window->DC.ColumnsOffset.x = 0.0f; + window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x); window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding; }