Tables: fixed dragging a header to reorder outside of visible bounds (due to horizontal scrolling) from losing active id.

This commit is contained in:
ocornut
2026-04-01 20:03:30 +02:00
parent 9df0d38d45
commit 6603cdef98
3 changed files with 7 additions and 2 deletions

View File

@@ -702,6 +702,7 @@ void ImGui::TableBeginApplyRequests(ImGuiTable* table)
// Note: we don't clear ReorderColumn after handling the request (FIXME: clarify why or add a test).
if (table->InstanceCurrent == 0)
{
table->LastHeldHeaderColumn = table->HeldHeaderColumn;
table->HeldHeaderColumn = -1;
if (table->ReorderColumn != -1 && table->ReorderColumnDstOrder != -1)
{
@@ -3136,7 +3137,7 @@ void ImGui::TableHeadersRow()
const int columns_count = TableGetColumnCount();
for (int column_n = 0; column_n < columns_count; column_n++)
{
if (!TableSetColumnIndex(column_n))
if (!TableSetColumnIndex(column_n) && table->LastHeldHeaderColumn != column_n)
continue;
// Push an id to allow empty/unnamed headers. This is also idiomatic as it ensure there is a consistent ID path to access columns (for e.g. automation)
@@ -4064,7 +4065,7 @@ void ImGui::DebugNodeTable(ImGuiTable* table)
BulletText("ColumnsGivenWidth: %.1f, ColumnsAutoFitWidth: %.1f, InnerWidth: %.1f%s", table->ColumnsGivenWidth, table->ColumnsAutoFitWidth, table->InnerWidth, table->InnerWidth == 0.0f ? " (auto)" : "");
BulletText("CellPaddingX: %.1f, CellSpacingX: %.1f/%.1f, OuterPaddingX: %.1f", table->CellPaddingX, table->CellSpacingX1, table->CellSpacingX2, table->OuterPaddingX);
BulletText("HoveredColumnBody: %d, HoveredColumnBorder: %d", table->HoveredColumnBody, table->HoveredColumnBorder);
BulletText("ResizedColumn: %d, HeldHeaderColumn: %d, ReorderColumn: %d", table->ResizedColumn, table->HeldHeaderColumn, table->ReorderColumn);
BulletText("ResizedColumn: %d, HeldHeaderColumn: %d, ReorderColumn: %d", table->LastResizedColumn, table->LastHeldHeaderColumn, table->ReorderColumn);
for (int n = 0; n < table->InstanceCurrent + 1; n++)
{
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, n);