From 5ef7b831c2bb90ab9c583426c91a0f5740413995 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 23 Nov 2020 17:02:00 +0100 Subject: [PATCH] Tables: removed ImGuiTableSortSpecs::ColumnsMask because it needlessly exposes our 64-columns limitation which we'd eventually would like to lift + shuffle declarations in internals --- imgui.h | 5 ++--- imgui_internal.h | 18 ++++++++++-------- imgui_tables.cpp | 6 ++---- imgui_widgets.cpp | 4 ++-- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/imgui.h b/imgui.h index 00fe0a2b..5ea11c81 100644 --- a/imgui.h +++ b/imgui.h @@ -1115,7 +1115,7 @@ enum ImGuiTableColumnFlags_ // [Internal] Combinations and masks ImGuiTableColumnFlags_WidthMask_ = ImGuiTableColumnFlags_WidthStretch | ImGuiTableColumnFlags_WidthFixed | ImGuiTableColumnFlags_WidthAutoResize, ImGuiTableColumnFlags_IndentMask_ = ImGuiTableColumnFlags_IndentEnable | ImGuiTableColumnFlags_IndentDisable, - ImGuiTableColumnFlags_NoDirectResize_ = 1 << 20 // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) + ImGuiTableColumnFlags_NoDirectResize_ = 1 << 30 // [Internal] Disable user resizing this column directly (it may however we resized indirectly from its left edge) }; // Flags for ImGui::TableNextRow() @@ -1912,9 +1912,8 @@ struct ImGuiTableSortSpecs const ImGuiTableSortSpecsColumn* 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. - ImU64 ColumnsMask; // Set to the mask of column indexes included in the Specs array. e.g. (1 << N) when column N is sorted. - ImGuiTableSortSpecs() { Specs = NULL; SpecsCount = 0; SpecsDirty = false; ColumnsMask = 0x00; } + ImGuiTableSortSpecs() { Specs = NULL; SpecsCount = 0; SpecsDirty = false; } }; //----------------------------------------------------------------------------- diff --git a/imgui_internal.h b/imgui_internal.h index ca5b0255..f0435efc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2270,21 +2270,25 @@ namespace ImGui IMGUI_API float GetColumnOffsetFromNorm(const ImGuiOldColumns* columns, float offset_norm); IMGUI_API float GetColumnNormFromOffset(const ImGuiOldColumns* columns, float offset); - // Tables + // Tables: Candidates for public api + IMGUI_API void TableOpenContextMenu(int column_n = -1); + IMGUI_API void TableSetColumnWidth(int column_n, float width); + IMGUI_API bool TableGetColumnIsHidden(int column_n); + IMGUI_API void TableSetColumnIsHidden(int column_n, bool hidden); + IMGUI_API void TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs); + IMGUI_API void TablePushBackgroundChannel(); + IMGUI_API void TablePopBackgroundChannel(); + + // Tables: Internals IMGUI_API ImGuiTable* TableFindByID(ImGuiID id); IMGUI_API bool BeginTableEx(const char* name, ImGuiID id, int columns_count, ImGuiTableFlags flags = 0, const ImVec2& outer_size = ImVec2(0, 0), float inner_width = 0.0f); IMGUI_API void TableBeginUpdateColumns(ImGuiTable* table); IMGUI_API void TableUpdateDrawChannels(ImGuiTable* table); IMGUI_API void TableUpdateLayout(ImGuiTable* table); IMGUI_API void TableUpdateBorders(ImGuiTable* table); - IMGUI_API void TableSetColumnWidth(int column_n, float width); - IMGUI_API bool TableGetColumnIsHidden(int column_n); - IMGUI_API void TableSetColumnIsHidden(int column_n, bool hidden); IMGUI_API void TableDrawBorders(ImGuiTable* table); IMGUI_API void TableDrawContextMenu(ImGuiTable* table); - IMGUI_API void TableOpenContextMenu(int column_n = -1); IMGUI_API void TableReorderDrawChannelsForMerge(ImGuiTable* table); - IMGUI_API void TableSetColumnSortDirection(int column_n, ImGuiSortDirection sort_direction, bool append_to_sort_specs); IMGUI_API void TableSortSpecsSanitize(ImGuiTable* table); IMGUI_API void TableSortSpecsBuild(ImGuiTable* table); IMGUI_API void TableBeginRow(ImGuiTable* table); @@ -2296,8 +2300,6 @@ namespace ImGui IMGUI_API ImGuiID TableGetColumnResizeID(const ImGuiTable* table, int column_n, int instance_no = 0); IMGUI_API void TableSetColumnWidthAutoSingle(ImGuiTable* table, int column_n); IMGUI_API void TableSetColumnWidthAutoAll(ImGuiTable* table); - IMGUI_API void PushTableBackground(); - IMGUI_API void PopTableBackground(); IMGUI_API void TableRemove(ImGuiTable* table); IMGUI_API void TableGcCompactTransientBuffers(ImGuiTable* table); IMGUI_API void TableGcCompactSettings(); diff --git a/imgui_tables.cpp b/imgui_tables.cpp index d933f6e6..f38e1b55 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -2129,7 +2129,7 @@ void ImGui::TableSetColumnWidthAutoAll(ImGuiTable* table) } } -void ImGui::PushTableBackground() +void ImGui::TablePushBackgroundChannel() { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; @@ -2141,7 +2141,7 @@ void ImGui::PushTableBackground() table->DrawSplitter.SetCurrentChannel(window->DrawList, table->Bg1DrawChannelCurrent); } -void ImGui::PopTableBackground() +void ImGui::TablePopBackgroundChannel() { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; @@ -2653,7 +2653,6 @@ void ImGui::TableSortSpecsBuild(ImGuiTable* table) // Write output table->SortSpecsData.resize(table->SortSpecsCount); - table->SortSpecs.ColumnsMask = 0x00; for (int column_n = 0; column_n < table->ColumnsCount; column_n++) { ImGuiTableColumn* column = &table->Columns[column_n]; @@ -2664,7 +2663,6 @@ void ImGui::TableSortSpecsBuild(ImGuiTable* table) sort_spec->ColumnIndex = (ImU8)column_n; sort_spec->SortOrder = (ImU8)column->SortOrder; sort_spec->SortDirection = column->SortDirection; - table->SortSpecs.ColumnsMask |= (ImU64)1 << column_n; } table->SortSpecs.Specs = table->SortSpecsData.Data; table->SortSpecs.SpecsCount = table->SortSpecsData.Size; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3eb56e3a..04abea08 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6000,7 +6000,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (span_all_columns && window->DC.CurrentColumns) PushColumnsBackground(); else if (span_all_columns && g.CurrentTable) - PushTableBackground(); + TablePushBackgroundChannel(); // We use NoHoldingActiveID on menus so user can click and _hold_ on a menu then drag to browse child entries ImGuiButtonFlags button_flags = 0; @@ -6050,7 +6050,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl if (span_all_columns && window->DC.CurrentColumns) PopColumnsBackground(); else if (span_all_columns && g.CurrentTable) - PopTableBackground(); + TablePopBackgroundChannel(); if (flags & ImGuiSelectableFlags_Disabled) PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]); RenderTextClipped(text_min, text_max, label, NULL, &label_size, style.SelectableTextAlign, &bb);