From 68bd43b2b455168571f99794132df136cc45329e Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 5 Oct 2026 18:00:45 +0200 Subject: [PATCH] Tables: fixed a bug tracking topology changes (insert new columns in the middle) when the table is not Reorderable. (#9570, #9108, #9572) --- docs/CHANGELOG.txt | 3 +++ imgui_tables.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e0d0d9264..e341b0296 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -76,6 +76,9 @@ Other Changes: - Tables: - Fixed a bug restoring correct .ini columns order when table use is Sortable but had no user changes. (regression from 1.92.9). (#9519, #9108) + - Fixed a bug tracking topology changes (insert new columns in the middle) + when the table is not _Reorderable: new columns would be ordered incorrectly. + (#9570, #9108, #9572) [@lailoken] - InpuText: - Fixed a crash in some cases when using Home key in a WordWrap+ReadOnly field. (#9561) - Selectable: diff --git a/imgui_tables.cpp b/imgui_tables.cpp index b3e0458eb..5ba6cb28f 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -4107,6 +4107,12 @@ static int IMGUI_CDECL TableFixDisplayOrderComparer(const void* lhs, const void* // Fix invalid display order data: compact values (0,1,3 -> 0,1,2); preserve relative order (0,3,1 -> 0,2,1); deduplicate (0,4,1,1 -> 0,3,1,2) void ImGui::TableFixDisplayOrder(ImGuiTable* table) { + if ((table->Flags & ImGuiTableFlags_Reorderable) == 0) + { + for (int n = 0; n < table->ColumnsCount; n++) + table->DisplayOrderToIndex[n] = table->Columns[n].DisplayOrder = (ImGuiTableColumnIdx)n; + return; + } ImGuiContext& g = *GImGui; g.TempBuffer.reserve((int)(sizeof(ImGuiTableFixDisplayOrderColumnData) * table->ColumnsCount)); // FIXME: Maybe wrap those two lines as a helper. ImGuiTableFixDisplayOrderColumnData* fdo_columns = (ImGuiTableFixDisplayOrderColumnData*)(void*)g.TempBuffer.Data;