[gtk/columnview-layout] columnview: Split gtk_column_view_allocate_columns



commit f6da3246708ad2a40c7be35adf15444200f2447d
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 5 11:24:55 2020 -0400

    columnview: Split gtk_column_view_allocate_columns
    
    Split off a helper function that just distributes
    the widths, without actually allocating the columns.
    
    This will be used in measuring in the future.

 gtk/gtkcolumnview.c        | 44 +++++++++++++++++++++++++++++++++++++-------
 gtk/gtkcolumnviewprivate.h |  5 +++++
 2 files changed, 42 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 85da86d482..46fb357147 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -236,19 +236,19 @@ gtk_column_view_measure (GtkWidget      *widget,
     }
 }
 
-static int
-gtk_column_view_allocate_columns (GtkColumnView *self,
-                                  int            width)
+void
+gtk_column_view_distribute_width (GtkColumnView    *self,
+                                  int               width,
+                                  GtkRequestedSize *sizes)
 {
   GtkScrollablePolicy scroll_policy;
-  int col_min, col_nat, extra, col_size, x;
+  int col_min, col_nat, extra, col_size;
   int n, n_expand, expand_size, n_extra;
   guint i;
-  GtkRequestedSize *sizes;
 
   n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
   n_expand = 0;
-  sizes = g_newa (GtkRequestedSize, n);
+
   for (i = 0; i < n; i++)
     {
       GtkColumnViewColumn *column;
@@ -282,7 +282,6 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
   else
     expand_size = n_extra = 0;
 
-  x = 0;
   for (i = 0; i < n; i++)
     {
       GtkColumnViewColumn *column;
@@ -300,6 +299,37 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
                   n_extra--;
                 }
             }
+          sizes[i].minimum_size = col_size;
+        }
+
+      g_object_unref (column);
+    }
+}
+
+static int
+gtk_column_view_allocate_columns (GtkColumnView *self,
+                                  int            width)
+{
+  guint i, n;
+  int x;
+  GtkRequestedSize *sizes;
+
+  n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
+
+  sizes = g_newa (GtkRequestedSize, n);
+
+  gtk_column_view_distribute_width (self, width, sizes);
+
+  x = 0;
+  for (i = 0; i < n; i++)
+    {
+      GtkColumnViewColumn *column;
+      int col_size;
+
+      column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+      if (gtk_column_view_column_get_visible (column))
+        {
+          col_size = sizes[i].minimum_size;
 
           gtk_column_view_column_allocate (column, x, col_size);
           if (self->in_column_reorder && i == self->drag_pos)
diff --git a/gtk/gtkcolumnviewprivate.h b/gtk/gtkcolumnviewprivate.h
index 8343c26144..2d080b9aa5 100644
--- a/gtk/gtkcolumnviewprivate.h
+++ b/gtk/gtkcolumnviewprivate.h
@@ -22,6 +22,7 @@
 
 #include "gtk/gtkcolumnview.h"
 #include "gtk/gtklistview.h"
+#include "gtk/gtksizerequest.h"
 
 #include "gtk/gtkcolumnviewsorterprivate.h"
 #include "gtk/gtklistitemwidgetprivate.h"
@@ -33,4 +34,8 @@ void                    gtk_column_view_measure_across          (GtkColumnView
                                                                  int                    *minimum,
                                                                  int                    *natural);
 
+void                    gtk_column_view_distribute_width        (GtkColumnView    *self,
+                                                                 int               width,
+                                                                 GtkRequestedSize *sizes);
+
 #endif  /* __GTK_COLUMN_VIEW_PRIVATE_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]