Browse Source

Tables: fixed a bug where after disabling the ScrollY flag for a table, previous scrollbar width would be accounted for. (#5920)

Amend 317b33d6
ocornut 1 year ago
parent
commit
68a05e3f04
2 changed files with 6 additions and 2 deletions
  1. 2 0
      docs/CHANGELOG.txt
  2. 4 2
      imgui_tables.cpp

+ 2 - 0
docs/CHANGELOG.txt

@@ -49,6 +49,8 @@ Other changes:
   grab scrolls by one page, holding mouse button repeats scrolling. (#7328, #150)
   grab scrolls by one page, holding mouse button repeats scrolling. (#7328, #150)
 - Scrollbar: fixed miscalculation of vertical scrollbar visibility when required
 - Scrollbar: fixed miscalculation of vertical scrollbar visibility when required
   solely by the presence of an horizontal scrollbar. (#1574)
   solely by the presence of an horizontal scrollbar. (#1574)
+- Tables: fixed a bug where after disabling the ScrollY flag for a table,
+  previous scrollbar width would be accounted for. (#5920)
 - Combo: simplified Combo() API uses a list clipper (due to its api it wasn't
 - Combo: simplified Combo() API uses a list clipper (due to its api it wasn't
   previously trivial before we added clipper.IncludeItemByIndex() function).
   previously trivial before we added clipper.IncludeItemByIndex() function).
 - Disabled: nested tooltips or other non-child window within a BeginDisabled()
 - Disabled: nested tooltips or other non-child window within a BeginDisabled()

+ 4 - 2
imgui_tables.cpp

@@ -437,6 +437,7 @@ bool    ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
         // For non-scrolling tables, WorkRect == OuterRect == InnerRect.
         // For non-scrolling tables, WorkRect == OuterRect == InnerRect.
         // But at this point we do NOT have a correct value for .Max.y (unless a height has been explicitly passed in). It will only be updated in EndTable().
         // But at this point we do NOT have a correct value for .Max.y (unless a height has been explicitly passed in). It will only be updated in EndTable().
         table->WorkRect = table->OuterRect = table->InnerRect = outer_rect;
         table->WorkRect = table->OuterRect = table->InnerRect = outer_rect;
+        table->HasScrollbarYPrev = table->HasScrollbarYCurr = false;
     }
     }
 
 
     // Push a standardized ID for both child-using and not-child-using tables
     // Push a standardized ID for both child-using and not-child-using tables
@@ -1490,9 +1491,10 @@ void    ImGui::EndTable()
     }
     }
     else if (temp_data->UserOuterSize.x <= 0.0f)
     else if (temp_data->UserOuterSize.x <= 0.0f)
     {
     {
+        const float inner_content_max_x = table->OuterRect.Min.x + table->ColumnsAutoFitWidth; // Slightly misleading name but used for code symmetry with inner_content_max_y
         const float decoration_size = table->TempData->AngledHeadersExtraWidth + ((table->Flags & ImGuiTableFlags_ScrollX) ? inner_window->ScrollbarSizes.x : 0.0f);
         const float decoration_size = table->TempData->AngledHeadersExtraWidth + ((table->Flags & ImGuiTableFlags_ScrollX) ? inner_window->ScrollbarSizes.x : 0.0f);
-        outer_window->DC.IdealMaxPos.x = ImMax(outer_window->DC.IdealMaxPos.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth + decoration_size - temp_data->UserOuterSize.x);
-        outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, ImMin(table->OuterRect.Max.x, table->OuterRect.Min.x + table->ColumnsAutoFitWidth));
+        outer_window->DC.IdealMaxPos.x = ImMax(outer_window->DC.IdealMaxPos.x, inner_content_max_x + decoration_size - temp_data->UserOuterSize.x);
+        outer_window->DC.CursorMaxPos.x = ImMax(backup_outer_max_pos.x, ImMin(table->OuterRect.Max.x, inner_content_max_x));
     }
     }
     else
     else
     {
     {