Skip to content

Commit 8db02ef

Browse files
committed
Tables: Fixed an issue with ScrollX enabled where an extraneous draw command would be created.
Randomly found while deep-diving into ocornut#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.
1 parent 947255c commit 8db02ef

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ Other changes:
109109
- Fixed bottom-most and right-most outer border offset by one. (#6765, #3752) [@v-ein]
110110
- Fixed top-most outer border being drawn with both TableBorderLight and TableBorderStrong
111111
in some situations, causing the earlier to be visible underneath when alpha is not 1.0f.
112-
- fixed right-clicking right-most section (past right-most column) from highlighting a column.
112+
- Fixed right-clicking right-most section (past right-most column) from highlighting a column.
113+
- Fixed an issue with ScrollX enabled where an extraneous draw command would be created.
113114
- TabBar: Fixed position of unsaved document marker (ImGuiTabItemFlags_UnsavedDocument) which was
114115
accidentally offset in 1.89.9. (#6862) [@alektron]
115116
- Fonts: 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer.

imgui_tables.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3015,21 +3015,24 @@ void ImGui::TableHeader(const char* label)
30153015
// Calculate ideal size for sort order arrow
30163016
float w_arrow = 0.0f;
30173017
float w_sort_text = 0.0f;
3018+
bool sort_arrow = false;
30183019
char sort_order_suf[4] = "";
30193020
const float ARROW_SCALE = 0.65f;
30203021
if ((table->Flags & ImGuiTableFlags_Sortable) && !(column->Flags & ImGuiTableColumnFlags_NoSort))
30213022
{
30223023
w_arrow = ImTrunc(g.FontSize * ARROW_SCALE + g.Style.FramePadding.x);
3024+
if (column->SortOrder != -1)
3025+
sort_arrow = true;
30233026
if (column->SortOrder > 0)
30243027
{
30253028
ImFormatString(sort_order_suf, IM_ARRAYSIZE(sort_order_suf), "%d", column->SortOrder + 1);
30263029
w_sort_text = g.Style.ItemInnerSpacing.x + CalcTextSize(sort_order_suf).x;
30273030
}
30283031
}
30293032

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

30353038
// Keep header highlighted when context menu is open.

0 commit comments

Comments
 (0)