Skip to content

Commit 6e38026

Browse files
committed
Tables: changelog. removed TableGetHoveredColumn() from public API in favor of using TableGetColumnFlags(). renamed ImGuiTableSortSpecsColumn to ImGuiTableColumnSortSpecs.
1 parent 7a61f34 commit 6e38026

File tree

6 files changed

+43
-17
lines changed

6 files changed

+43
-17
lines changed

docs/CHANGELOG.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ Breaking Changes:
5959

6060
Other Changes:
6161

62+
- Tables: added new Tables Beta API as a replacement for old Columns. (#2957, #125)
63+
Check out 'Demo->Tables' for many demos + API comments in imgui.h for details.
64+
- Added 16 functions: BeginTable(), EndTable(),
65+
TableNextRow(), TableNextColumn(), TableSetColumnIndex(), TableGetColumnIndex(), TableGetRowIndex(),
66+
TableSetupColumn(), TableSetupScrollFreeze(),
67+
TableHeadersRow(), TableHeader(), TableSetBgColor(), TableGetSortSpecs(),
68+
TableGetColumnCount(), TableGetColumnName(), TableGetColumnFlags().
69+
- Added 2 structures: ImGuiTableSortSpecs, ImGuiTableColumnSortSpecs.
70+
- Added 2 enums: ImGuiSortDirection, ImGuiTableBgTarget.
71+
- Added 3 flags sets: ImGuiTableFlags (27 flags), ImGuiTableColumnFlags (24 flags), ImGuiTableRowFlags (1 flags).
72+
- Added 5 colors: ImGuiCol_TableHeaderBg, ImGuiCol_TableBorderStrong, ImGuiCol_TableBorderLight, ImGuiCol_TableRowBg, ImGuiCol_TableRowBgAlt.
73+
- Added 1 style var: ImGuiStyleVar_CellPadding.
6274
- Tab Bar: Made it possible to append to an existing tab bar by calling BeginTabBar()/EndTabBar() again.
6375
- Tab Bar: Fixed using more than 128 tabs in a tab bar (scrolling policy recommended).
6476
- Tab Bar: Do not display a tooltip if the name already fits over a given tab. (#3521)

imgui.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Index of this file:
3333
// Draw List API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawListFlags, ImDrawList, ImDrawData)
3434
// Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont)
3535
36-
// FIXME-TABLE: Add ImGuiTableSortSpecsColumn and ImGuiTableSortSpecs in "Misc data structures" section above (we don't do it right now to facilitate merging various branches)
36+
// FIXME-TABLE: Add ImGuiTableSortSpecs and ImGuiTableColumnSortSpecs in "Misc data structures" section above (we don't do it right now to facilitate merging various branches)
3737
3838
*/
3939

@@ -139,7 +139,7 @@ struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSiz
139139
struct ImGuiStorage; // Helper for key->value storage
140140
struct ImGuiStyle; // Runtime data for styling/colors
141141
struct ImGuiTableSortSpecs; // Sorting specifications for a table (often handling sort specs for a single column, occasionally more)
142-
struct ImGuiTableSortSpecsColumn; // Sorting specification for one column of a table
142+
struct ImGuiTableColumnSortSpecs; // Sorting specification for one column of a table
143143
struct ImGuiTextBuffer; // Helper to hold and append into a text buffer (~string builder)
144144
struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbbb][,ccccc]")
145145

@@ -653,7 +653,7 @@ namespace ImGui
653653
IMGUI_API bool IsPopupOpen(const char* str_id, ImGuiPopupFlags flags = 0); // return true if the popup is open.
654654

655655
// Tables
656-
// [ALPHA API] API may evolve!
656+
// [BETA API] API may evolve!
657657
// - Full-featured replacement for old Columns API.
658658
// - See Demo->Tables for details.
659659
// - See ImGuiTableFlags_ and ImGuiTableColumnFlags_ enums for a description of available flags.
@@ -708,7 +708,6 @@ namespace ImGui
708708
IMGUI_API int TableGetColumnCount(); // return number of columns (value passed to BeginTable)
709709
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.
710710
IMGUI_API ImGuiTableColumnFlags TableGetColumnFlags(int column_n = -1); // return column flags so you can query their Enabled/Visible/Sorted/Hovered status flags.
711-
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.
712711
IMGUI_API ImGuiTableSortSpecs* TableGetSortSpecs(); // get latest sort specs for the table (NULL if not sorting).
713712
IMGUI_API void TableSetBgColor(ImGuiTableBgTarget bg_target, ImU32 color, int column_n = -1); // change the color of a cell, row, or column. See ImGuiTableBgTarget_ flags for details.
714713

@@ -1903,14 +1902,14 @@ struct ImGuiPayload
19031902
};
19041903

19051904
// Sorting specification for one column of a table (sizeof == 12 bytes)
1906-
struct ImGuiTableSortSpecsColumn
1905+
struct ImGuiTableColumnSortSpecs
19071906
{
19081907
ImGuiID ColumnUserID; // User id of the column (if specified by a TableSetupColumn() call)
19091908
ImS16 ColumnIndex; // Index of the column
19101909
ImS16 SortOrder; // Index within parent ImGuiTableSortSpecs (always stored in order starting from 0, tables sorted on a single criteria will always have a 0 here)
19111910
ImGuiSortDirection SortDirection : 8; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending (you can use this or SortSign, whichever is more convenient for your sort function)
19121911

1913-
ImGuiTableSortSpecsColumn() { memset(this, 0, sizeof(*this)); }
1912+
ImGuiTableColumnSortSpecs() { memset(this, 0, sizeof(*this)); }
19141913
};
19151914

19161915
// Sorting specifications for a table (often handling sort specs for a single column, occasionally more)
@@ -1919,7 +1918,7 @@ struct ImGuiTableSortSpecsColumn
19191918
// Make sure to set 'SpecsDirty = false' after sorting, else you may wastefully sort your data every frame!
19201919
struct ImGuiTableSortSpecs
19211920
{
1922-
const ImGuiTableSortSpecsColumn* Specs; // Pointer to sort spec array.
1921+
const ImGuiTableColumnSortSpecs* Specs; // Pointer to sort spec array.
19231922
int SpecsCount; // Sort spec count. Most often 1 unless e.g. ImGuiTableFlags_MultiSortable is enabled.
19241923
bool SpecsDirty; // Set to true when specs have changed since last time! Use this to sort again, then clear the flag.
19251924

imgui_demo.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,21 @@
3838
// and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h.
3939
// Because we can't assume anything about your support of maths operators, we cannot use them in imgui_demo.cpp.
4040

41+
// Navigating this file:
42+
// - In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot.
43+
// - With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments.
44+
4145
/*
4246
4347
Index of this file:
4448
4549
// [SECTION] Forward Declarations, Helpers
4650
// [SECTION] Demo Window / ShowDemoWindow()
51+
// - sub section: ShowDemoWindowWidgets()
52+
// - sub section: ShowDemoWindowLayout()
53+
// - sub section: ShowDemoWindowPopups()
54+
// - sub section: ShowDemoWindowTables()
55+
// - sub section: ShowDemoWindowMisc()
4756
// [SECTION] About Window / ShowAboutWindow()
4857
// [SECTION] Style Editor / ShowStyleEditor()
4958
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
@@ -3303,7 +3312,7 @@ struct MyItem
33033312
{
33043313
// Here we identify columns using the ColumnUserID value that we ourselves passed to TableSetupColumn()
33053314
// We could also choose to identify columns based on their index (sort_spec->ColumnIndex), which is simpler!
3306-
const ImGuiTableSortSpecsColumn* sort_spec = &s_current_sort_specs->Specs[n];
3315+
const ImGuiTableColumnSortSpecs* sort_spec = &s_current_sort_specs->Specs[n];
33073316
int delta = 0;
33083317
switch (sort_spec->ColumnUserID)
33093318
{
@@ -3755,7 +3764,7 @@ static void ShowDemoWindowTables()
37553764
sprintf(buf, "Hello %d,%d", column, row);
37563765
ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f));
37573766
}
3758-
//if (ImGui::TableGetHoveredColumn() == column)
3767+
//if (ImGui::TableGetColumnFlags() & ImGuiTableColumnFlags_IsHovered)
37593768
// ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, IM_COL32(0, 100, 0, 255));
37603769
}
37613770
}
@@ -4460,10 +4469,12 @@ static void ShowDemoWindowTables()
44604469
// [2.3] Right-click anywhere in columns to open another custom popup
44614470
// (instead of testing for !IsAnyItemHovered() we could also call OpenPopup() with ImGuiPopupFlags_NoOpenOverExistingPopup
44624471
// to manage popup priority as the popups triggers, here "are we hovering a column" are overlapping)
4463-
const int hovered_column = ImGui::TableGetHoveredColumn();
4472+
int hovered_column = -1;
44644473
for (int column = 0; column < COLUMNS_COUNT + 1; column++)
44654474
{
44664475
ImGui::PushID(column);
4476+
if (ImGui::TableGetColumnFlags(column) & ImGuiTableColumnFlags_IsHovered)
4477+
hovered_column = column;
44674478
if (hovered_column == column && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(1))
44684479
ImGui::OpenPopup("MyPopup");
44694480
if (ImGui::BeginPopup("MyPopup"))
@@ -4480,7 +4491,7 @@ static void ShowDemoWindowTables()
44804491
}
44814492

44824493
ImGui::EndTable();
4483-
ImGui::Text("TableGetHoveredColumn() returned: %d", hovered_column);
4494+
ImGui::Text("Hovered column: %d", hovered_column);
44844495
}
44854496
ImGui::TreePop();
44864497
}

imgui_draw.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst)
226226
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); // Prefer using Alpha=1.0 here
227227
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); // Prefer using Alpha=1.0 here
228228
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
229-
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
229+
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
230230
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
231231
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
232232
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
@@ -347,7 +347,7 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst)
347347
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.57f, 0.57f, 0.64f, 1.00f); // Prefer using Alpha=1.0 here
348348
colors[ImGuiCol_TableBorderLight] = ImVec4(0.68f, 0.68f, 0.74f, 1.00f); // Prefer using Alpha=1.0 here
349349
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
350-
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.30f, 0.30f, 0.30f, 0.07f);
350+
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.30f, 0.30f, 0.30f, 0.09f);
351351
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
352352
colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
353353
colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];

imgui_internal.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2027,8 +2027,8 @@ struct ImGuiTable
20272027
ImGuiWindow* InnerWindow; // Window holding the table data (== OuterWindow or a child window)
20282028
ImGuiTextBuffer ColumnsNames; // Contiguous buffer holding columns names
20292029
ImDrawListSplitter DrawSplitter; // We carry our own ImDrawList splitter to allow recursion (FIXME: could be stored outside, worst case we need 1 splitter per recursing table)
2030-
ImGuiTableSortSpecsColumn SortSpecsSingle;
2031-
ImVector<ImGuiTableSortSpecsColumn> SortSpecsMulti; // FIXME-OPT: Using a small-vector pattern would work be good.
2030+
ImGuiTableColumnSortSpecs SortSpecsSingle;
2031+
ImVector<ImGuiTableColumnSortSpecs> SortSpecsMulti; // FIXME-OPT: Using a small-vector pattern would work be good.
20322032
ImGuiTableSortSpecs SortSpecs; // Public facing sorts specs, this is what we return in TableGetSortSpecs()
20332033
ImGuiTableColumnIdx SortSpecsCount;
20342034
ImGuiTableColumnIdx ColumnsEnabledCount; // Number of enabled columns (<= ColumnsCount)
@@ -2286,6 +2286,7 @@ namespace ImGui
22862286
IMGUI_API void TableSetColumnWidth(int column_n, float width);
22872287
IMGUI_API void TableSetColumnIsEnabled(int column_n, bool enabled);
22882288
IMGUI_API void TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs);
2289+
IMGUI_API int TableGetHoveredColumn(); // May use (TableGetColumnFlags() & ImGuiTableColumnFlags_IsHovered) instead. 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.
22892290
IMGUI_API float TableGetHeaderRowHeight();
22902291
IMGUI_API void TablePushBackgroundChannel();
22912292
IMGUI_API void TablePopBackgroundChannel();

imgui_tables.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,7 @@ const char* ImGui::TableGetColumnName(int column_n)
17791779
return TableGetColumnName(table, column_n);
17801780
}
17811781

1782+
// We allow querying for an extra column in order to poll the IsHovered state of the right-most section
17821783
ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n)
17831784
{
17841785
ImGuiContext& g = *GImGui;
@@ -1787,6 +1788,8 @@ ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n)
17871788
return ImGuiTableColumnFlags_None;
17881789
if (column_n < 0)
17891790
column_n = table->CurrentColumn;
1791+
if (column_n == table->ColumnsCount)
1792+
return (table->HoveredColumnBody == column_n) ? ImGuiTableColumnFlags_IsHovered : ImGuiTableColumnFlags_None;
17901793
return table->Columns[column_n].Flags;
17911794
}
17921795

@@ -2452,14 +2455,14 @@ void ImGui::TableSortSpecsBuild(ImGuiTable* table)
24522455
// Write output
24532456
const bool single_sort_specs = (table->SortSpecsCount <= 1);
24542457
table->SortSpecsMulti.resize(single_sort_specs ? 0 : table->SortSpecsCount);
2455-
ImGuiTableSortSpecsColumn* sort_specs = single_sort_specs ? &table->SortSpecsSingle : table->SortSpecsMulti.Data;
2458+
ImGuiTableColumnSortSpecs* sort_specs = single_sort_specs ? &table->SortSpecsSingle : table->SortSpecsMulti.Data;
24562459
for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
24572460
{
24582461
ImGuiTableColumn* column = &table->Columns[column_n];
24592462
if (column->SortOrder == -1)
24602463
continue;
24612464
IM_ASSERT(column->SortOrder < table->SortSpecsCount);
2462-
ImGuiTableSortSpecsColumn* sort_spec = &sort_specs[column->SortOrder];
2465+
ImGuiTableColumnSortSpecs* sort_spec = &sort_specs[column->SortOrder];
24632466
sort_spec->ColumnUserID = column->UserID;
24642467
sort_spec->ColumnIndex = (ImGuiTableColumnIdx)column_n;
24652468
sort_spec->SortOrder = (ImGuiTableColumnIdx)column->SortOrder;

0 commit comments

Comments
 (0)