Skip to content

Commit

Permalink
Tables: Fixed an issue with ScrollX enabled where an extraneous draw …
Browse files Browse the repository at this point in the history
…command would be created.

Randomly found while deep-diving into #6765.
ContentMaxXHeadersUsed has been set to max since the dawn of tables, which contradict the intent of passing zero-width to ItemSize(). The ItemSize code allowed SameLine() to operate, but this mistake setting ContentMaxXHeadersUsed would make right-most visible column in a ScrollX set incorrectly use a draw command due to header claiming whole column width.
  • Loading branch information
ocornut committed Oct 16, 2023
1 parent 947255c commit 8db02ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ Other changes:
- Fixed bottom-most and right-most outer border offset by one. (#6765, #3752) [@v-ein]
- 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.
- Fixed right-clicking right-most section (past right-most column) from highlighting a column.
- Fixed an issue with ScrollX enabled where an extraneous draw command would be created.
- TabBar: Fixed position of unsaved document marker (ImGuiTabItemFlags_UnsavedDocument) which was
accidentally offset in 1.89.9. (#6862) [@alektron]
- Fonts: 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer.
Expand Down
7 changes: 5 additions & 2 deletions imgui_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3015,21 +3015,24 @@ void ImGui::TableHeader(const char* label)
// Calculate ideal size for sort order arrow
float w_arrow = 0.0f;
float w_sort_text = 0.0f;
bool sort_arrow = false;
char sort_order_suf[4] = "";
const float ARROW_SCALE = 0.65f;
if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
{
w_arrow = ImTrunc(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x);
if (column->SortOrder != -1)
sort_arrow = true;
if (column->SortOrder > 0)
{
ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1);
w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x;
}
}

// We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considering for merging.
// We feed our unclipped width to the column without writing on CursorMaxPos, so that column is still considered for merging.
float max_pos_x = label_pos.x + label_size.x + w_sort_text + w_arrow;
column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, column->WorkMaxX);
column->ContentMaxXHeadersUsed = ImMax(column->ContentMaxXHeadersUsed, sort_arrow ? cell_r.Max.x : ImMin(max_pos_x, cell_r.Max.x));
column->ContentMaxXHeadersIdeal = ImMax(column->ContentMaxXHeadersIdeal, max_pos_x);

// Keep header highlighted when context menu is open.
Expand Down

0 comments on commit 8db02ef

Please sign in to comment.