Browse Source

Tables: Fix scroll when releasing resize for multi-instances. Comments. Renaming.

omar 5 years ago
parent
commit
1db8d421cf
2 changed files with 20 additions and 20 deletions
  1. 6 6
      imgui_internal.h
  2. 14 14
      imgui_tables.cpp

+ 6 - 6
imgui_internal.h

@@ -1932,8 +1932,8 @@ struct ImGuiTable
     ImS8                        HoveredColumnBody;          // [DEBUG] Unlike HoveredColumnBorder this doesn't fulfill all Hovering rules properly. Used for debugging/tools for now.
     ImS8                        HoveredColumnBody;          // [DEBUG] Unlike HoveredColumnBorder this doesn't fulfill all Hovering rules properly. Used for debugging/tools for now.
     ImS8                        HoveredColumnBorder;        // Index of column whose right-border is being hovered (for resizing).
     ImS8                        HoveredColumnBorder;        // Index of column whose right-border is being hovered (for resizing).
     ImS8                        ResizedColumn;              // Index of column being resized. Reset by InstanceNo==0.
     ImS8                        ResizedColumn;              // Index of column being resized. Reset by InstanceNo==0.
-    ImS8                        HeadHeaderColumn;           // Index of column header being held. 
-    ImS8                        LastResizedColumn;
+    ImS8                        LastResizedColumn;          // Index of column being resized from previous frame.
+    ImS8                        HeldHeaderColumn;           // Index of column header being held. 
     ImS8                        ReorderColumn;              // Index of column being reordered. (not cleared)
     ImS8                        ReorderColumn;              // Index of column being reordered. (not cleared)
     ImS8                        ReorderColumnDir;           // -1 or +1
     ImS8                        ReorderColumnDir;           // -1 or +1
     ImS8                        RightMostActiveColumn;      // Index of right-most non-hidden column.
     ImS8                        RightMostActiveColumn;      // Index of right-most non-hidden column.
@@ -1945,11 +1945,11 @@ struct ImGuiTable
     ImS8                        FreezeColumnsRequest;       // Requested frozen columns count
     ImS8                        FreezeColumnsRequest;       // Requested frozen columns count
     ImS8                        FreezeColumnsCount;         // Actual frozen columns count (== FreezeColumnsRequest, or == 0 when no scrolling offset)
     ImS8                        FreezeColumnsCount;         // Actual frozen columns count (== FreezeColumnsRequest, or == 0 when no scrolling offset)
     bool                        IsLayoutLocked;             // Set by TableUpdateLayout() which is called when beginning the first row.
     bool                        IsLayoutLocked;             // Set by TableUpdateLayout() which is called when beginning the first row.
-    bool                        IsInsideRow;                // Set if inside TableBeginRow()/TableEndRow().
-    bool                        IsFirstFrame;
+    bool                        IsInsideRow;                // Set when inside TableBeginRow()/TableEndRow().
+    bool                        IsInitializing;
     bool                        IsSortSpecsDirty;
     bool                        IsSortSpecsDirty;
-    bool                        IsUsingHeaders;             // Set if the first row had the ImGuiTableRowFlags_Headers flag.
-    bool                        IsContextPopupOpen;
+    bool                        IsUsingHeaders;             // Set when the first row had the ImGuiTableRowFlags_Headers flag.
+    bool                        IsContextPopupOpen;         // Set when default context menu is open (also see: ContextPopupColumn, InstanceInteracted).
     bool                        IsSettingsRequestLoad;
     bool                        IsSettingsRequestLoad;
     bool                        IsSettingsLoaded;
     bool                        IsSettingsLoaded;
     bool                        IsSettingsDirty;            // Set when table settings have changed and needs to be reported into ImGuiTableSetttings data.
     bool                        IsSettingsDirty;            // Set when table settings have changed and needs to be reported into ImGuiTableSetttings data.

+ 14 - 14
imgui_tables.cpp

@@ -61,6 +61,7 @@
 // [SECTION] Widgets: BeginTable, EndTable, etc.
 // [SECTION] Widgets: BeginTable, EndTable, etc.
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
+//-----------------------------------------------------------------------------
 // Typical call flow: (root level is public API):
 // Typical call flow: (root level is public API):
 // - BeginTable()                               user begin into a table
 // - BeginTable()                               user begin into a table
 //    - BeginChild()                            - (if ScrollX/ScrollY is set)
 //    - BeginChild()                            - (if ScrollX/ScrollY is set)
@@ -81,6 +82,7 @@
 //    - TableSetColumnWidth()                   - apply resizing width
 //    - TableSetColumnWidth()                   - apply resizing width
 //      - TableUpdateColumnsWeightFromWidth()
 //      - TableUpdateColumnsWeightFromWidth()
 //      - EndChild()                            - (if ScrollX/ScrollY is set)
 //      - EndChild()                            - (if ScrollX/ScrollY is set)
+//-----------------------------------------------------------------------------
 
 
 // Configuration
 // Configuration
 static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4.0f;    // Extend outside inner borders.
 static const float TABLE_RESIZE_SEPARATOR_HALF_THICKNESS = 4.0f;    // Extend outside inner borders.
@@ -190,12 +192,12 @@ bool    ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
     // Initialize
     // Initialize
     table->ID = id;
     table->ID = id;
     table->Flags = flags;
     table->Flags = flags;
-    table->IsFirstFrame = (table->LastFrameActive == -1);
     table->InstanceNo = (ImS16)instance_no;
     table->InstanceNo = (ImS16)instance_no;
     table->LastFrameActive = g.FrameCount;
     table->LastFrameActive = g.FrameCount;
     table->OuterWindow = table->InnerWindow = outer_window;
     table->OuterWindow = table->InnerWindow = outer_window;
     table->ColumnsCount = columns_count;
     table->ColumnsCount = columns_count;
     table->ColumnsNames.Buf.resize(0);
     table->ColumnsNames.Buf.resize(0);
+    table->IsInitializing = false;
     table->IsLayoutLocked = false;
     table->IsLayoutLocked = false;
     table->InnerWidth = inner_width;
     table->InnerWidth = inner_width;
     table->OuterRect = outer_rect;
     table->OuterRect = outer_rect;
@@ -256,11 +258,9 @@ bool    ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
     table->FreezeColumnsCount = (inner_window->Scroll.x != 0.0f) ? table->FreezeColumnsRequest : 0;
     table->FreezeColumnsCount = (inner_window->Scroll.x != 0.0f) ? table->FreezeColumnsRequest : 0;
     table->IsFreezeRowsPassed = (table->FreezeRowsCount == 0);
     table->IsFreezeRowsPassed = (table->FreezeRowsCount == 0);
     table->DeclColumnsCount = 0;
     table->DeclColumnsCount = 0;
-    table->LastResizedColumn = table->ResizedColumn;
     table->HoveredColumnBody = -1;
     table->HoveredColumnBody = -1;
     table->HoveredColumnBorder = -1;
     table->HoveredColumnBorder = -1;
     table->RightMostActiveColumn = -1;
     table->RightMostActiveColumn = -1;
-    table->IsFirstFrame = false;
 
 
     // FIXME-TABLE FIXME-STYLE: Using opaque colors facilitate overlapping elements of the grid
     // FIXME-TABLE FIXME-STYLE: Using opaque colors facilitate overlapping elements of the grid
     //table->BorderOuterColor = GetColorU32(ImGuiCol_Separator, 1.00f);
     //table->BorderOuterColor = GetColorU32(ImGuiCol_Separator, 1.00f);
@@ -289,8 +289,7 @@ bool    ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
     // Setup default columns state
     // Setup default columns state
     if (table->Columns.Size == 0)
     if (table->Columns.Size == 0)
     {
     {
-        table->IsFirstFrame = true;
-        table->IsSortSpecsDirty = true;
+        table->IsInitializing = table->IsSettingsRequestLoad = table->IsSortSpecsDirty = true;
         table->Columns.reserve(columns_count);
         table->Columns.reserve(columns_count);
         table->DisplayOrder.reserve(columns_count);
         table->DisplayOrder.reserve(columns_count);
         for (int n = 0; n < columns_count; n++)
         for (int n = 0; n < columns_count; n++)
@@ -303,7 +302,7 @@ bool    ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
     }
     }
 
 
     // Load settings
     // Load settings
-    if (table->IsFirstFrame || table->IsSettingsRequestLoad)
+    if (table->IsSettingsRequestLoad)
         TableLoadSettings(table);
         TableLoadSettings(table);
 
 
     // Grab a copy of window fields we will modify
     // Grab a copy of window fields we will modify
@@ -332,6 +331,7 @@ void ImGui::TableBeginUpdateColumns(ImGuiTable* table)
     {
     {
         if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX)
         if (table->ResizedColumn != -1 && table->ResizedColumnNextWidth != FLT_MAX)
             TableSetColumnWidth(table, &table->Columns[table->ResizedColumn], table->ResizedColumnNextWidth);
             TableSetColumnWidth(table, &table->Columns[table->ResizedColumn], table->ResizedColumnNextWidth);
+        table->LastResizedColumn = table->ResizedColumn;
         table->ResizedColumnNextWidth = FLT_MAX;
         table->ResizedColumnNextWidth = FLT_MAX;
         table->ResizedColumn = -1;
         table->ResizedColumn = -1;
     }
     }
@@ -340,9 +340,9 @@ void ImGui::TableBeginUpdateColumns(ImGuiTable* table)
     // Note: we don't clear ReorderColumn after handling the request.
     // Note: we don't clear ReorderColumn after handling the request.
     if (table->InstanceNo == 0)
     if (table->InstanceNo == 0)
     {
     {
-        if (table->HeadHeaderColumn == -1 && table->ReorderColumn != -1)
+        if (table->HeldHeaderColumn == -1 && table->ReorderColumn != -1)
             table->ReorderColumn = -1;
             table->ReorderColumn = -1;
-        table->HeadHeaderColumn = -1;
+        table->HeldHeaderColumn = -1;
         if (table->ReorderColumn != -1 && table->ReorderColumnDir != 0)
         if (table->ReorderColumn != -1 && table->ReorderColumnDir != 0)
         {
         {
             IM_ASSERT(table->ReorderColumnDir == -1 || table->ReorderColumnDir == +1);
             IM_ASSERT(table->ReorderColumnDir == -1 || table->ReorderColumnDir == +1);
@@ -554,10 +554,10 @@ void    ImGui::TableUpdateLayout(ImGuiTable* table)
                     width_request = ImMax(width_request, (float)column->ContentWidthHeadersDesired);
                     width_request = ImMax(width_request, (float)column->ContentWidthHeadersDesired);
                 column->WidthRequested = ImMax(width_request + padding_auto_x, min_column_width);
                 column->WidthRequested = ImMax(width_request + padding_auto_x, min_column_width);
 
 
-                // FIXME-TABLE: Increase minimum size during init frame so avoid biasing auto-fitting widgets (e.g. TextWrapped) too much.
+                // FIXME-TABLE: Increase minimum size during init frame to avoid biasing auto-fitting widgets (e.g. TextWrapped) too much.
                 // Otherwise what tends to happen is that TextWrapped would output a very large height (= first frame scrollbar display very off + clipper would skip lots of items)
                 // Otherwise what tends to happen is that TextWrapped would output a very large height (= first frame scrollbar display very off + clipper would skip lots of items)
                 // This is merely making the side-effect less extreme, but doesn't properly fixes it.
                 // This is merely making the side-effect less extreme, but doesn't properly fixes it.
-                if (column->AutoFitQueue > 0x01 && table->IsFirstFrame)
+                if (column->AutoFitQueue > 0x01 && table->IsInitializing)
                     column->WidthRequested = ImMax(column->WidthRequested, min_column_width * 4.0f);
                     column->WidthRequested = ImMax(column->WidthRequested, min_column_width * 4.0f);
             }
             }
             width_fixed += column->WidthRequested;
             width_fixed += column->WidthRequested;
@@ -929,7 +929,7 @@ void    ImGui::EndTable()
     {
     {
         inner_window->Scroll.x = 0.0f;
         inner_window->Scroll.x = 0.0f;
     }
     }
-    else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX)
+    else if (table->LastResizedColumn != -1 && table->ResizedColumn == -1 && inner_window->ScrollbarX && table->InstanceInteracted == table->InstanceNo)
     {
     {
         ImGuiTableColumn* column = &table->Columns[table->LastResizedColumn];
         ImGuiTableColumn* column = &table->Columns[table->LastResizedColumn];
         if (column->MaxX < table->InnerClipRect.Min.x)
         if (column->MaxX < table->InnerClipRect.Min.x)
@@ -1333,7 +1333,7 @@ void    ImGui::TableSetupColumn(const char* label, ImGuiTableColumnFlags flags,
     flags = column->Flags;
     flags = column->Flags;
 
 
     // Initialize defaults
     // Initialize defaults
-    if (table->IsFirstFrame && !table->IsSettingsLoaded)
+    if (table->IsInitializing && !table->IsSettingsLoaded)
     {
     {
         // Init width or weight
         // Init width or weight
         // Disable auto-fit if a default fixed width has been specified
         // Disable auto-fit if a default fixed width has been specified
@@ -1913,7 +1913,7 @@ void    ImGui::TableHeader(const char* label)
     const bool pressed = Selectable("", selected, ImGuiSelectableFlags_DrawHoveredWhenHeld, ImVec2(0.0f, row_height));
     const bool pressed = Selectable("", selected, ImGuiSelectableFlags_DrawHoveredWhenHeld, ImVec2(0.0f, row_height));
     const bool held = IsItemActive();
     const bool held = IsItemActive();
     if (held)
     if (held)
-        table->HeadHeaderColumn = (ImS8)column_n;
+        table->HeldHeaderColumn = (ImS8)column_n;
     window->DC.CursorPos.y -= g.Style.ItemSpacing.y * 0.5f;
     window->DC.CursorPos.y -= g.Style.ItemSpacing.y * 0.5f;
 
 
     // Drag and drop: re-order columns. Frozen columns are not reorderable.
     // Drag and drop: re-order columns. Frozen columns are not reorderable.
@@ -2123,7 +2123,7 @@ void ImGui::TableSortSpecsSanitize(ImGuiTable* table)
     }
     }
 
 
     // Fallback default sort order (if no column has the ImGuiTableColumnFlags_DefaultSort flag)
     // Fallback default sort order (if no column has the ImGuiTableColumnFlags_DefaultSort flag)
-    if (sort_order_count == 0 && table->IsFirstFrame)
+    if (sort_order_count == 0 && table->IsInitializing)
         for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
         for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
         {
         {
             ImGuiTableColumn* column = &table->Columns[column_n];
             ImGuiTableColumn* column = &table->Columns[column_n];