Browse Source

Tables: changelog. removed TableGetHoveredColumn() from public API in favor of using TableGetColumnFlags(). renamed ImGuiTableSortSpecsColumn to ImGuiTableColumnSortSpecs.

pull/3657/head
ocornut 4 years ago
parent
commit
6e38026627
  1. 12
      docs/CHANGELOG.txt
  2. 13
      imgui.h
  3. 19
      imgui_demo.cpp
  4. 4
      imgui_draw.cpp
  5. 5
      imgui_internal.h
  6. 7
      imgui_tables.cpp

12
docs/CHANGELOG.txt

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

13
imgui.h

@ -33,7 +33,7 @@ Index of this file:
// Draw List API (ImDrawCallback, ImDrawCmd, ImDrawIdx, ImDrawVert, ImDrawChannel, ImDrawListSplitter, ImDrawListFlags, ImDrawList, ImDrawData)
// Font API (ImFontConfig, ImFontGlyph, ImFontGlyphRangesBuilder, ImFontAtlasFlags, ImFontAtlas, ImFont)
// FIXME-TABLE: Add ImGuiTableSortSpecsColumn and ImGuiTableSortSpecs in "Misc data structures" section above (we don't do it right now to facilitate merging various branches)
// FIXME-TABLE: Add ImGuiTableSortSpecs and ImGuiTableColumnSortSpecs in "Misc data structures" section above (we don't do it right now to facilitate merging various branches)
*/
@ -139,7 +139,7 @@ struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSiz
struct ImGuiStorage; // Helper for key->value storage
struct ImGuiStyle; // Runtime data for styling/colors
struct ImGuiTableSortSpecs; // Sorting specifications for a table (often handling sort specs for a single column, occasionally more)
struct ImGuiTableSortSpecsColumn; // Sorting specification for one column of a table
struct ImGuiTableColumnSortSpecs; // Sorting specification for one column of a table
struct ImGuiTextBuffer; // Helper to hold and append into a text buffer (~string builder)
struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbbb][,ccccc]")
@ -653,7 +653,7 @@ namespace ImGui
IMGUI_API bool IsPopupOpen(const char* str_id, ImGuiPopupFlags flags = 0); // return true if the popup is open.
// Tables
// [ALPHA API] API may evolve!
// [BETA API] API may evolve!
// - Full-featured replacement for old Columns API.
// - See Demo->Tables for details.
// - See ImGuiTableFlags_ and ImGuiTableColumnFlags_ enums for a description of available flags.
@ -708,7 +708,6 @@ namespace ImGui
IMGUI_API int TableGetColumnCount(); // return number of columns (value passed to BeginTable)
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.
IMGUI_API ImGuiTableColumnFlags TableGetColumnFlags(int column_n = -1); // return column flags so you can query their Enabled/Visible/Sorted/Hovered status flags.
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.
IMGUI_API ImGuiTableSortSpecs* TableGetSortSpecs(); // get latest sort specs for the table (NULL if not sorting).
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.
@ -1903,14 +1902,14 @@ struct ImGuiPayload
};
// Sorting specification for one column of a table (sizeof == 12 bytes)
struct ImGuiTableSortSpecsColumn
struct ImGuiTableColumnSortSpecs
{
ImGuiID ColumnUserID; // User id of the column (if specified by a TableSetupColumn() call)
ImS16 ColumnIndex; // Index of the column
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)
ImGuiSortDirection SortDirection : 8; // ImGuiSortDirection_Ascending or ImGuiSortDirection_Descending (you can use this or SortSign, whichever is more convenient for your sort function)
ImGuiTableSortSpecsColumn() { memset(this, 0, sizeof(*this)); }
ImGuiTableColumnSortSpecs() { memset(this, 0, sizeof(*this)); }
};
// Sorting specifications for a table (often handling sort specs for a single column, occasionally more)
@ -1919,7 +1918,7 @@ struct ImGuiTableSortSpecsColumn
// Make sure to set 'SpecsDirty = false' after sorting, else you may wastefully sort your data every frame!
struct ImGuiTableSortSpecs
{
const ImGuiTableSortSpecsColumn* Specs; // Pointer to sort spec array.
const ImGuiTableColumnSortSpecs* Specs; // Pointer to sort spec array.
int SpecsCount; // Sort spec count. Most often 1 unless e.g. ImGuiTableFlags_MultiSortable is enabled.
bool SpecsDirty; // Set to true when specs have changed since last time! Use this to sort again, then clear the flag.

19
imgui_demo.cpp

@ -38,12 +38,21 @@
// and require you either enable those, either provide your own via IM_VEC2_CLASS_EXTRA in imconfig.h.
// Because we can't assume anything about your support of maths operators, we cannot use them in imgui_demo.cpp.
// Navigating this file:
// - In Visual Studio IDE: CTRL+comma ("Edit.NavigateTo") can follow symbols in comments, whereas CTRL+F12 ("Edit.GoToImplementation") cannot.
// - With Visual Assist installed: ALT+G ("VAssistX.GoToImplementation") can also follow symbols in comments.
/*
Index of this file:
// [SECTION] Forward Declarations, Helpers
// [SECTION] Demo Window / ShowDemoWindow()
// - sub section: ShowDemoWindowWidgets()
// - sub section: ShowDemoWindowLayout()
// - sub section: ShowDemoWindowPopups()
// - sub section: ShowDemoWindowTables()
// - sub section: ShowDemoWindowMisc()
// [SECTION] About Window / ShowAboutWindow()
// [SECTION] Style Editor / ShowStyleEditor()
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
@ -3303,7 +3312,7 @@ struct MyItem
{
// Here we identify columns using the ColumnUserID value that we ourselves passed to TableSetupColumn()
// We could also choose to identify columns based on their index (sort_spec->ColumnIndex), which is simpler!
const ImGuiTableSortSpecsColumn* sort_spec = &s_current_sort_specs->Specs[n];
const ImGuiTableColumnSortSpecs* sort_spec = &s_current_sort_specs->Specs[n];
int delta = 0;
switch (sort_spec->ColumnUserID)
{
@ -3755,7 +3764,7 @@ static void ShowDemoWindowTables()
sprintf(buf, "Hello %d,%d", column, row);
ImGui::Button(buf, ImVec2(-FLT_MIN, 0.0f));
}
//if (ImGui::TableGetHoveredColumn() == column)
//if (ImGui::TableGetColumnFlags() & ImGuiTableColumnFlags_IsHovered)
// ImGui::TableSetBgColor(ImGuiTableBgTarget_CellBg, IM_COL32(0, 100, 0, 255));
}
}
@ -4460,10 +4469,12 @@ static void ShowDemoWindowTables()
// [2.3] Right-click anywhere in columns to open another custom popup
// (instead of testing for !IsAnyItemHovered() we could also call OpenPopup() with ImGuiPopupFlags_NoOpenOverExistingPopup
// to manage popup priority as the popups triggers, here "are we hovering a column" are overlapping)
const int hovered_column = ImGui::TableGetHoveredColumn();
int hovered_column = -1;
for (int column = 0; column < COLUMNS_COUNT + 1; column++)
{
ImGui::PushID(column);
if (ImGui::TableGetColumnFlags(column) & ImGuiTableColumnFlags_IsHovered)
hovered_column = column;
if (hovered_column == column && !ImGui::IsAnyItemHovered() && ImGui::IsMouseReleased(1))
ImGui::OpenPopup("MyPopup");
if (ImGui::BeginPopup("MyPopup"))
@ -4480,7 +4491,7 @@ static void ShowDemoWindowTables()
}
ImGui::EndTable();
ImGui::Text("TableGetHoveredColumn() returned: %d", hovered_column);
ImGui::Text("Hovered column: %d", hovered_column);
}
ImGui::TreePop();
}

4
imgui_draw.cpp

@ -226,7 +226,7 @@ void ImGui::StyleColorsDark(ImGuiStyle* dst)
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.31f, 0.31f, 0.35f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableBorderLight] = ImVec4(0.23f, 0.23f, 0.25f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.07f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.06f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(1.00f, 1.00f, 0.00f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
@ -347,7 +347,7 @@ void ImGui::StyleColorsLight(ImGuiStyle* dst)
colors[ImGuiCol_TableBorderStrong] = ImVec4(0.57f, 0.57f, 0.64f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableBorderLight] = ImVec4(0.68f, 0.68f, 0.74f, 1.00f); // Prefer using Alpha=1.0 here
colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.30f, 0.30f, 0.30f, 0.07f);
colors[ImGuiCol_TableRowBgAlt] = ImVec4(0.30f, 0.30f, 0.30f, 0.09f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
colors[ImGuiCol_NavHighlight] = colors[ImGuiCol_HeaderHovered];

5
imgui_internal.h

@ -2027,8 +2027,8 @@ struct ImGuiTable
ImGuiWindow* InnerWindow; // Window holding the table data (== OuterWindow or a child window)
ImGuiTextBuffer ColumnsNames; // Contiguous buffer holding columns names
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)
ImGuiTableSortSpecsColumn SortSpecsSingle;
ImVector<ImGuiTableSortSpecsColumn> SortSpecsMulti; // FIXME-OPT: Using a small-vector pattern would work be good.
ImGuiTableColumnSortSpecs SortSpecsSingle;
ImVector<ImGuiTableColumnSortSpecs> SortSpecsMulti; // FIXME-OPT: Using a small-vector pattern would work be good.
ImGuiTableSortSpecs SortSpecs; // Public facing sorts specs, this is what we return in TableGetSortSpecs()
ImGuiTableColumnIdx SortSpecsCount;
ImGuiTableColumnIdx ColumnsEnabledCount; // Number of enabled columns (<= ColumnsCount)
@ -2286,6 +2286,7 @@ namespace ImGui
IMGUI_API void TableSetColumnWidth(int column_n, float width);
IMGUI_API void TableSetColumnIsEnabled(int column_n, bool enabled);
IMGUI_API void TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs);
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.
IMGUI_API float TableGetHeaderRowHeight();
IMGUI_API void TablePushBackgroundChannel();
IMGUI_API void TablePopBackgroundChannel();

7
imgui_tables.cpp

@ -1779,6 +1779,7 @@ const char* ImGui::TableGetColumnName(int column_n)
return TableGetColumnName(table, column_n);
}
// We allow querying for an extra column in order to poll the IsHovered state of the right-most section
ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n)
{
ImGuiContext& g = *GImGui;
@ -1787,6 +1788,8 @@ ImGuiTableColumnFlags ImGui::TableGetColumnFlags(int column_n)
return ImGuiTableColumnFlags_None;
if (column_n < 0)
column_n = table->CurrentColumn;
if (column_n == table->ColumnsCount)
return (table->HoveredColumnBody == column_n) ? ImGuiTableColumnFlags_IsHovered : ImGuiTableColumnFlags_None;
return table->Columns[column_n].Flags;
}
@ -2452,14 +2455,14 @@ void ImGui::TableSortSpecsBuild(ImGuiTable* table)
// Write output
const bool single_sort_specs = (table->SortSpecsCount <= 1);
table->SortSpecsMulti.resize(single_sort_specs ? 0 : table->SortSpecsCount);
ImGuiTableSortSpecsColumn* sort_specs = single_sort_specs ? &table->SortSpecsSingle : table->SortSpecsMulti.Data;
ImGuiTableColumnSortSpecs* sort_specs = single_sort_specs ? &table->SortSpecsSingle : table->SortSpecsMulti.Data;
for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
{
ImGuiTableColumn* column = &table->Columns[column_n];
if (column->SortOrder == -1)
continue;
IM_ASSERT(column->SortOrder < table->SortSpecsCount);
ImGuiTableSortSpecsColumn* sort_spec = &sort_specs[column->SortOrder];
ImGuiTableColumnSortSpecs* sort_spec = &sort_specs[column->SortOrder];
sort_spec->ColumnUserID = column->UserID;
sort_spec->ColumnIndex = (ImGuiTableColumnIdx)column_n;
sort_spec->SortOrder = (ImGuiTableColumnIdx)column->SortOrder;

Loading…
Cancel
Save