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

@@ -92,6 +92,9 @@ Other Changes:
buffer on the IsItemDeactivatedAfterEdit() frame. This could create issues when buffer on the IsItemDeactivatedAfterEdit() frame. This could create issues when
using the idiom of not applying edits before IsItemDeactivatedAfterEdit(). using the idiom of not applying edits before IsItemDeactivatedAfterEdit().
(#9308, #8915, #8273) (#9308, #8915, #8273)
- Tables:
- Fixed dragging a header to reorder outside of visible bounds (due to horizontal scrolling)
from losing active id.
- Style: - Style:
- Border sizes are now scaled (and rounded) by ScaleAllSizes(). - Border sizes are now scaled (and rounded) by ScaleAllSizes().
- When using large values with ScallAllSizes(), the following items thickness - When using large values with ScallAllSizes(), the following items thickness

View File

@@ -3044,6 +3044,7 @@ struct IMGUI_API ImGuiTable
ImGuiTableColumnIdx ResizedColumn; // Index of column being resized. Reset when InstanceCurrent==0. ImGuiTableColumnIdx ResizedColumn; // Index of column being resized. Reset when InstanceCurrent==0.
ImGuiTableColumnIdx LastResizedColumn; // Index of column being resized from previous frame. ImGuiTableColumnIdx LastResizedColumn; // Index of column being resized from previous frame.
ImGuiTableColumnIdx HeldHeaderColumn; // Index of column header being held. ImGuiTableColumnIdx HeldHeaderColumn; // Index of column header being held.
ImGuiTableColumnIdx LastHeldHeaderColumn; // Index of column header being held from previous frame.
ImGuiTableColumnIdx ReorderColumn; // Index of column being reordered. (not cleared) ImGuiTableColumnIdx ReorderColumn; // Index of column being reordered. (not cleared)
ImGuiTableColumnIdx ReorderColumnDstOrder; // Requested display order of column being reordered. ImGuiTableColumnIdx ReorderColumnDstOrder; // Requested display order of column being reordered.
ImGuiTableColumnIdx LeftMostEnabledColumn; // Index of left-most non-hidden column. ImGuiTableColumnIdx LeftMostEnabledColumn; // Index of left-most non-hidden column.

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). // Note: we don't clear ReorderColumn after handling the request (FIXME: clarify why or add a test).
if (table->InstanceCurrent == 0) if (table->InstanceCurrent == 0)
{ {
table->LastHeldHeaderColumn = table->HeldHeaderColumn;
table->HeldHeaderColumn = -1; table->HeldHeaderColumn = -1;
if (table->ReorderColumn != -1 && table->ReorderColumnDstOrder != -1) if (table->ReorderColumn != -1 && table->ReorderColumnDstOrder != -1)
{ {
@@ -3136,7 +3137,7 @@ void ImGui::TableHeadersRow()
const int columns_count = TableGetColumnCount(); const int columns_count = TableGetColumnCount();
for (int column_n = 0; column_n < columns_count; column_n++) for (int column_n = 0; column_n < columns_count; column_n++)
{ {
if (!TableSetColumnIndex(column_n)) if (!TableSetColumnIndex(column_n) && table->LastHeldHeaderColumn != column_n)
continue; 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) // 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("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("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("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++) for (int n = 0; n < table->InstanceCurrent + 1; n++)
{ {
ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, n); ImGuiTableInstanceData* table_instance = TableGetInstanceData(table, n);