Skip to content

Commit

Permalink
Columns: Improved honoring alignment with various values of ItemSpaci…
Browse files Browse the repository at this point in the history
…ng.x and WindowPadding.x. (#125, #2666)
  • Loading branch information
ocornut committed Jul 19, 2019
1 parent 4abc2a8 commit b443bc0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Other Changes:
- 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)
- Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#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]
Expand Down
11 changes: 6 additions & 5 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7307,9 +7307,10 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
// 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 + half_clip_extend_x - window->Pos.x;
columns->OffMaxX = ImMax(columns->OffMaxX, columns->OffMinX + 1.0f);
const float max_1 = window->WorkRect.Max.x + column_padding - ImMax(column_padding - window->WindowPadding.x, 0.0f);
const float max_2 = window->WorkRect.Max.x + half_clip_extend_x;
columns->OffMinX = window->DC.Indent.x - column_padding + ImMax(column_padding - window->WindowPadding.x, 0.0f);
columns->OffMaxX = ImMax(ImMin(max_1, max_2) - window->Pos.x, columns->OffMinX + 1.0f);
columns->LineMinY = columns->LineMaxY = window->DC.CursorPos.y;

// Clear data if columns count changed
Expand Down Expand Up @@ -7351,7 +7352,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag
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.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.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;
}
Expand Down Expand Up @@ -7387,7 +7388,7 @@ void ImGui::NextColumn()
{
// New row/line
// Column 0 honor IndentX
window->DC.ColumnsOffset.x = 0.0f;
window->DC.ColumnsOffset.x = ImMax(column_padding - window->WindowPadding.x, 0.0f);
window->DrawList->ChannelsSetCurrent(1);
columns->Current = 0;
columns->LineMinY = columns->LineMaxY;
Expand Down

0 comments on commit b443bc0

Please sign in to comment.