Browse Source

Tables: Fixed an edge-case when no columns are visible + table scrollbar is visible + user code is always testing return value of TableSetColumnIndex() to coarse clip.

ocornut 2 years ago
parent
commit
c32db3c72b
2 changed files with 14 additions and 0 deletions
  1. 3 0
      docs/CHANGELOG.txt
  2. 11 0
      imgui_tables.cpp

+ 3 - 0
docs/CHANGELOG.txt

@@ -59,6 +59,9 @@ Other changes:
 - Nav: Tabbing always enable nav highlight when ImGuiConfigFlags_NavEnableKeyboard is set.
   Previously was inconsistent and only enabled when stepping through a non-input item.
   (#6802, #3092, #5759, #787)
+- Tables: Fixed an edge-case when no columns are visible + table scrollbar is visible + user
+  code is always testing return value of TableSetColumnIndex() to coarse clip. With an active
+  clipper it would have asserted. Without a clipper, the scrollbar range would be wrong.
 - Tables: Request user to submit contents when outer host-window is requesting auto-resize,
   so a scrolling table can contribute to initial window size. (#6510)
 - Tables: Fixed subtle drawing overlap between borders in some situations.

+ 11 - 0
imgui_tables.cpp

@@ -985,6 +985,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
     // [Part 6] Setup final position, offset, skip/clip states and clipping rectangles, detect hovered column
     // Process columns in their visible orders as we are comparing the visible order and adjusting host_clip_rect while looping.
     int visible_n = 0;
+    bool has_at_least_one_column_requesting_output = false;
     bool offset_x_frozen = (table->FreezeColumnsCount > 0);
     float offset_x = ((table->FreezeColumnsCount > 0) ? table->OuterRect.Min.x : work_rect.Min.x) + table->OuterPaddingX - table->CellSpacingX1;
     ImRect host_clip_rect = table->InnerClipRect;
@@ -1069,6 +1070,8 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
         column->IsSkipItems = !column->IsEnabled || table->HostSkipItems;
         if (column->IsSkipItems)
             IM_ASSERT(!is_visible);
+        if (column->IsRequestOutput && !column->IsSkipItems)
+            has_at_least_one_column_requesting_output = true;
 
         // Update status flags
         column->Flags |= ImGuiTableColumnFlags_IsEnabled;
@@ -1106,6 +1109,14 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
         visible_n++;
     }
 
+    // In case the table is visible (e.g. decorations) but all columns clipped, we keep a column visible.
+    // Else if give no chance to a clipper-savy user to submit rows and therefore total contents height used by scrollbar.
+    if (has_at_least_one_column_requesting_output == false)
+    {
+        table->Columns[table->LeftMostEnabledColumn].IsRequestOutput = true;
+        table->Columns[table->LeftMostEnabledColumn].IsSkipItems = false;
+    }
+
     // [Part 7] Detect/store when we are hovering the unused space after the right-most column (so e.g. context menus can react on it)
     // Clear Resizable flag if none of our column are actually resizable (either via an explicit _NoResize flag, either
     // because of using _WidthAuto/_WidthStretch). This will hide the resizing option from the context menu.