Skip to content

Commit e09454a

Browse files
committed
Tables: removed TableGetColumnIsVisible from public api, re-specced as TableGetColumnIsHidden() returning same flag as setter, clipper increase CurrentRow.
1 parent a70c6aa commit e09454a

File tree

4 files changed

+31
-28
lines changed

4 files changed

+31
-28
lines changed

imgui.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2207,7 +2207,9 @@ static void SetCursorPosYAndSetupForPrevLine(float pos_y, float line_height)
22072207
if (table->IsInsideRow)
22082208
ImGui::TableEndRow(table);
22092209
table->RowPosY2 = window->DC.CursorPos.y;
2210-
table->RowBgColorCounter += (int)((off_y / line_height) + 0.5f);
2210+
const int row_increase = (int)((off_y / line_height) + 0.5f);
2211+
//table->CurrentRow += row_increase; // Can't do without fixing TableEndRow()
2212+
table->RowBgColorCounter += row_increase;
22112213
}
22122214
}
22132215

imgui.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ namespace ImGui
682682
IMGUI_API bool BeginTable(const char* str_id, int columns_count, ImGuiTableFlags flags = 0, const ImVec2& outer_size = ImVec2(0, 0), float inner_width = 0.0f);
683683
IMGUI_API void EndTable(); // only call EndTable() if BeginTable() returns true!
684684
IMGUI_API void TableNextRow(ImGuiTableRowFlags row_flags = 0, float min_row_height = 0.0f); // append into the first cell of a new row.
685-
IMGUI_API bool TableNextColumn(); // append into the next column (or first column of next row if currently in last column). Return false when column is not visible.
686-
IMGUI_API bool TableSetColumnIndex(int column_n); // append into the specified column. Return false when column is not visible.
685+
IMGUI_API bool TableNextColumn(); // append into the next column (or first column of next row if currently in last column). Return true when column is visible.
686+
IMGUI_API bool TableSetColumnIndex(int column_n); // append into the specified column. Return true when column is visible.
687687
IMGUI_API int TableGetColumnIndex(); // return current column index.
688688
IMGUI_API int TableGetRowIndex(); // return current row index.
689689
// Tables: Headers & Columns declaration
@@ -705,7 +705,6 @@ namespace ImGui
705705
// Lifetime: don't hold on this pointer over multiple frames or past any subsequent call to BeginTable().
706706
IMGUI_API int TableGetColumnCount(); // return number of columns (value passed to BeginTable)
707707
IMGUI_API const char* TableGetColumnName(int column_n = -1); // return "" if column didn't have a name declared by TableSetupColumn(). Pass -1 to use current column.
708-
IMGUI_API bool TableGetColumnIsVisible(int column_n = -1); // return true if column is visible. Same value is also returned by TableNextColumn() and TableSetColumnIndex(). Pass -1 to use current column.
709708
IMGUI_API bool TableGetColumnIsSorted(int column_n = -1); // return true if column is included in the sort specs. Rarely used, can be useful to tell if a data change should trigger resort. Equivalent to test ImGuiTableSortSpecs's ->ColumnsMask & (1 << column_n). Pass -1 to use current column.
710709
IMGUI_API int TableGetHoveredColumn(); // return hovered column. return -1 when table is not hovered. return columns_count if the unused space at the right of visible columns is hovered.
711710
IMGUI_API ImGuiTableSortSpecs* TableGetSortSpecs(); // get latest sort specs for the table (NULL if not sorting).

imgui_internal.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,8 @@ struct ImGuiTabBar
18941894
#define IMGUI_TABLE_MAX_DRAW_CHANNELS (4 + 64 * 2) // See TableUpdateDrawChannels()
18951895

18961896
// [Internal] sizeof() ~ 104
1897-
// We use the terminology "Visible" to refer to a column that is not Hidden by user or settings. However it may still be out of view and clipped (see IsClipped).
1897+
// We use the terminology "Visible" to refer to a columns that are not Hidden by user or settings. However it may still be out of view and clipped (and IsClipped would be set).
1898+
// This is in contrast with some user-facing api such as IsItemVisible() / IsRectVisible() which use "Visible" to mean "not clipped".
18981899
struct ImGuiTableColumn
18991900
{
19001901
ImRect ClipRect; // Clipping rectangle for the column
@@ -2277,7 +2278,8 @@ namespace ImGui
22772278
IMGUI_API void TableUpdateLayout(ImGuiTable* table);
22782279
IMGUI_API void TableUpdateBorders(ImGuiTable* table);
22792280
IMGUI_API void TableSetColumnWidth(int column_n, float width);
2280-
IMGUI_API void TableSetColumnVisible(int column_n, bool visible);
2281+
IMGUI_API bool TableGetColumnIsHidden(int column_n);
2282+
IMGUI_API void TableSetColumnIsHidden(int column_n, bool hidden);
22812283
IMGUI_API void TableDrawBorders(ImGuiTable* table);
22822284
IMGUI_API void TableDrawContextMenu(ImGuiTable* table);
22832285
IMGUI_API void TableOpenContextMenu(int column_n = -1);

imgui_tables.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ bool ImGui::BeginTable(const char* str_id, int columns_count, ImGuiTableFlags
200200
return BeginTableEx(str_id, id, columns_count, flags, outer_size, inner_width);
201201
}
202202

203-
// For reference, the total _allocation count_ for a table is:
203+
// For reference, the average total _allocation count_ for a table is:
204204
// + 0 (for ImGuiTable instance, we are pooling allocations in g.Tables)
205205
// + 1 (for table->RawData allocated below)
206206
// + 1 (for table->ColumnsNames, if names are used)
@@ -878,7 +878,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
878878

879879
column->IsClipped = (column->ClipRect.Max.x <= column->ClipRect.Min.x) && (column->AutoFitQueue & 1) == 0 && (column->CannotSkipItemsQueue & 1) == 0;
880880
if (column->IsClipped)
881-
table->VisibleUnclippedMaskByIndex &= ~((ImU64)1 << column_n); // Columns with the _WidthAutoResize sizing policy will never be updated then.
881+
table->VisibleUnclippedMaskByIndex &= ~((ImU64)1 << column_n); // Columns with the _WidthAutoResize sizing policy will never be updated then.
882882

883883
column->IsSkipItems = !column->IsVisible || table->HostSkipItems;
884884

@@ -1386,16 +1386,6 @@ void ImGui::TableSetColumnWidth(int column_n, float width)
13861386
}
13871387
}
13881388

1389-
// Public wrapper
1390-
void ImGui::TableSetColumnVisible(int column_n, bool visible)
1391-
{
1392-
ImGuiContext& g = *GImGui;
1393-
ImGuiTable* table = g.CurrentTable;
1394-
IM_ASSERT(table != NULL && table->IsLayoutLocked == false);
1395-
IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
1396-
table->Columns[column_n].IsVisibleNextFrame = visible;
1397-
}
1398-
13991389
// Allocate draw channels. Called by TableUpdateLayout()
14001390
// - We allocate them following storage order instead of display order so reordering columns won't needlessly
14011391
// increase overall dormant memory cost.
@@ -2038,16 +2028,27 @@ const char* ImGui::TableGetColumnName(int column_n)
20382028
return TableGetColumnName(table, column_n);
20392029
}
20402030

2041-
// We expose "Visible and Unclipped" to the user, vs our internal "Visible" state which is !Hidden
2042-
bool ImGui::TableGetColumnIsVisible(int column_n)
2031+
// FIXME-TABLE: Also expose "Visible and Unclipped" to the user, vs our internal "Visible" state which is !Hidden
2032+
bool ImGui::TableGetColumnIsHidden(int column_n)
20432033
{
20442034
ImGuiContext& g = *GImGui;
20452035
ImGuiTable* table = g.CurrentTable;
20462036
if (!table)
20472037
return false;
20482038
if (column_n < 0)
20492039
column_n = table->CurrentColumn;
2050-
return (table->VisibleUnclippedMaskByIndex & ((ImU64)1 << column_n)) != 0;
2040+
return (table->VisibleMaskByIndex & ((ImU64)1 << column_n)) == 0;
2041+
}
2042+
2043+
void ImGui::TableSetColumnIsHidden(int column_n, bool hidden)
2044+
{
2045+
ImGuiContext& g = *GImGui;
2046+
ImGuiTable* table = g.CurrentTable;
2047+
IM_ASSERT(table != NULL && table->IsLayoutLocked == false);
2048+
if (column_n < 0)
2049+
column_n = table->CurrentColumn;
2050+
IM_ASSERT(column_n >= 0 && column_n < table->ColumnsCount);
2051+
table->Columns[column_n].IsVisibleNextFrame = !hidden;
20512052
}
20522053

20532054
int ImGui::TableGetColumnIndex()
@@ -2059,6 +2060,7 @@ int ImGui::TableGetColumnIndex()
20592060
return table->CurrentColumn;
20602061
}
20612062

2063+
// Note: for row coloring we use ->RowBgColorCounter which is the same value without counting header rows
20622064
int ImGui::TableGetRowIndex()
20632065
{
20642066
ImGuiContext& g = *GImGui;
@@ -2275,7 +2277,7 @@ void ImGui::TableHeadersRow()
22752277
const float row_y1 = GetCursorScreenPos().y;
22762278
const int columns_count = TableGetColumnCount();
22772279
for (int column_n = 0; column_n < columns_count; column_n++)
2278-
if (TableGetColumnIsVisible(column_n))
2280+
if (!TableGetColumnIsHidden(column_n))
22792281
row_height = ImMax(row_height, CalcTextSize(TableGetColumnName(column_n)).y);
22802282
row_height += style.CellPadding.y * 2.0f;
22812283

@@ -3051,19 +3053,17 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
30513053
const char* name = TableGetColumnName(table, n);
30523054
ImFormatString(buf, IM_ARRAYSIZE(buf),
30533055
"Column %d order %d name '%s': offset %+.2f to %+.2f\n"
3054-
"Visible: %d, Clipped: %d, DrawChannels: %d,%d\n"
3056+
"Visible: %d, Clipped: %d, SkipItems: %d, DrawChannels: %d,%d\n"
30553057
"WidthGiven: %.1f, Request/Auto: %.1f/%.1f, StretchWeight: %.3f\n"
30563058
"MinX: %.1f, MaxX: %.1f (%+.1f), ClipRect: %.1f to %.1f (+%.1f)\n"
30573059
"ContentWidth: %.1f,%.1f, HeadersUsed/Ideal %.1f/%.1f\n"
3058-
"SortOrder: %d, SortDir: %s\n"
3059-
"UserID: 0x%08X, Flags: 0x%04X: %s%s%s%s..",
3060+
"Sort: %d%s, UserID: 0x%08X, Flags: 0x%04X: %s%s%s%s..",
30603061
n, column->DisplayOrder, name, column->MinX - table->WorkRect.Min.x, column->MaxX - table->WorkRect.Min.x,
3061-
column->IsVisible, column->IsClipped, column->DrawChannelFrozen, column->DrawChannelUnfrozen,
3062+
column->IsVisible, column->IsClipped, column->IsSkipItems, column->DrawChannelFrozen, column->DrawChannelUnfrozen,
30623063
column->WidthGiven, column->WidthRequest, column->WidthAuto, column->StretchWeight,
30633064
column->MinX, column->MaxX, column->MaxX - column->MinX, column->ClipRect.Min.x, column->ClipRect.Max.x, column->ClipRect.Max.x - column->ClipRect.Min.x,
30643065
column->ContentMaxXFrozen - column->WorkMinX, column->ContentMaxXUnfrozen - column->WorkMinX, column->ContentMaxXHeadersUsed - column->WorkMinX, column->ContentMaxXHeadersIdeal - column->WorkMinX,
3065-
column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? "Ascending" : (column->SortDirection == ImGuiSortDirection_Descending) ? "Descending" : "None",
3066-
column->UserID, column->Flags,
3066+
column->SortOrder, (column->SortDirection == ImGuiSortDirection_Ascending) ? " (Asc)" : (column->SortDirection == ImGuiSortDirection_Descending) ? " (Des)" : "", column->UserID, column->Flags,
30673067
(column->Flags & ImGuiTableColumnFlags_WidthStretch) ? "WidthStretch " : "",
30683068
(column->Flags & ImGuiTableColumnFlags_WidthFixed) ? "WidthFixed " : "",
30693069
(column->Flags & ImGuiTableColumnFlags_WidthAutoResize) ? "WidthAutoResize " : "",

0 commit comments

Comments
 (0)