Skip to content

Commit b443bc0

Browse files
committed
Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#125, #2666)
1 parent 4abc2a8 commit b443bc0

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

docs/CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Other Changes:
6161
- Columns: Made the right-most edge reaches up to the clipping rectangle (removing half of WindowPadding.x
6262
worth of asymmetrical/extraneous padding, note that there's another half that conservatively has to offset
6363
the right-most column, otherwise it's clipping width won't match the other column). (#125, #2666)
64+
- Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#125, #2666)
6465
- Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because
6566
of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d).
6667
- Scrolling: Added SetScrollHereX(), SetScrollFromPosX() for completeness. (#1580) [@kevreco]

imgui_widgets.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -7307,9 +7307,10 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
73077307
// We aim so that the right-most column will have the same clipping width as other after being clipped by parent ClipRect
73087308
const float column_padding = g.Style.ItemSpacing.x;
73097309
const float half_clip_extend_x = ImFloor(ImMax(window->WindowPadding.x * 0.5f, window->WindowBorderSize));
7310-
columns->OffMinX = window->DC.Indent.x - column_padding;
7311-
columns->OffMaxX = window->WorkRect.Max.x + half_clip_extend_x - window->Pos.x;
7312-
columns->OffMaxX = ImMax(columns->OffMaxX, columns->OffMinX + 1.0f);
7310+
const float max_1 = window->WorkRect.Max.x + column_padding - ImMax(column_padding - window->WindowPadding.x, 0.0f);
7311+
const float max_2 = window->WorkRect.Max.x + half_clip_extend_x;
7312+
columns->OffMinX = window->DC.Indent.x - column_padding + ImMax(column_padding - window->WindowPadding.x, 0.0f);
7313+
columns->OffMaxX = ImMax(ImMin(max_1, max_2) - window->Pos.x, columns->OffMinX + 1.0f);
73137314
columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;
73147315

73157316
// Clear data if columns count changed
@@ -7351,7 +7352,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
73517352
float offset_1 = GetColumnOffset(columns->Current + 1);
73527353
float width = offset_1 - offset_0;
73537354
PushItemWidth(width * 0.65f);
7354-
window->DC.ColumnsOffset.x = 0.0f;
7355+
window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
73557356
window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.Indent.x + window->DC.ColumnsOffset.x);
73567357
window->WorkRect.Max.x = window->Pos.x + offset_1 - column_padding;
73577358
}
@@ -7387,7 +7388,7 @@ void ImGui::NextColumn()
73877388
{
73887389
// New row/line
73897390
// Column 0 honor IndentX
7390-
window->DC.ColumnsOffset.x = 0.0f;
7391+
window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
73917392
window->DrawList->ChannelsSetCurrent(1);
73927393
columns->Current = 0;
73937394
columns->LineMinY = columns->LineMaxY;

0 commit comments

Comments
 (0)