[gtk/prop-list: 25/27] columnview: Implement GTK_SCROLL_FIT



commit 1aa5c11f3d5f3256dd6ea93500f1c8a3bdf4f6f3
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 16 19:22:03 2019 -0500

    columnview: Implement GTK_SCROLL_FIT
    
    Make columns take a size between min and nat
    for this policy.

 gtk/gtkcolumnview.c | 65 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 32a2bea66c..c4e0702696 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -34,6 +34,7 @@
 #include "gtkprivate.h"
 #include "gtkscrollable.h"
 #include "gtkwidgetprivate.h"
+#include "gtksizerequest.h"
 
 /**
  * SECTION:gtkcolumnview
@@ -170,46 +171,62 @@ gtk_column_view_allocate_columns (GtkColumnView *self,
   GtkScrollablePolicy scroll_policy;
   int col_min, col_nat, widget_min, widget_nat, extra, col_size, x;
   guint i;
+  int n;
+  GtkRequestedSize *sizes;
+
+  n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
+  sizes = g_newa (GtkRequestedSize, n);
+  for (i = 0; i < n; i++)
+    {
+      GtkColumnViewColumn *column;
+
+      column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+      if (gtk_column_view_column_get_visible (column))
+        gtk_column_view_column_measure (column, &sizes[i].minimum_size, &sizes[i].natural_size);
+      else
+        sizes[i].minimum_size = sizes[i].natural_size = 0;
+      g_object_unref (column);
+    }
 
   gtk_column_view_measure_across (self, &col_min, &col_nat);
-  gtk_widget_measure (GTK_WIDGET (self),
-                      GTK_ORIENTATION_HORIZONTAL, -1,
-                      &widget_min, &widget_nat,
-                      NULL, NULL);
 
   scroll_policy = gtk_scrollable_get_hscroll_policy (GTK_SCROLLABLE (self->listview));
-  if (scroll_policy == GTK_SCROLL_MINIMUM)
-    {
-      extra = widget_min - col_min;
-      col_size = col_min;
-    }
-  else
+  if (scroll_policy == GTK_SCROLL_FIT)
     {
-      extra = widget_nat - col_nat;
-      col_size = col_nat;
+      if (width < col_min)
+        scroll_policy = GTK_SCROLL_MINIMUM;
+      else if (width > col_nat)
+        scroll_policy = GTK_SCROLL_NATURAL;
+      else
+        {
+          extra = MAX (width - col_min, 0);
+          gtk_distribute_natural_allocation (extra, n, sizes);
+        }
     }
-  width -= extra;
-  width = MAX (width, col_size);
 
   x = 0;
-  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->columns)); i++)
+  for (i = 0; i < n; i++)
     {
       GtkColumnViewColumn *column;
 
       column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
-      gtk_column_view_column_measure (column, &col_min, &col_nat);
-      if (scroll_policy == GTK_SCROLL_MINIMUM)
-        col_size = col_min;
-      else
-        col_size = col_nat;
-
-      gtk_column_view_column_allocate (column, x, col_size);
-      x += col_size;
+      if (gtk_column_view_column_get_visible (column))
+        {
+          if (scroll_policy == GTK_SCROLL_MINIMUM)
+            col_size = sizes[i].minimum_size;
+          else if (scroll_policy == GTK_SCROLL_NATURAL)
+            col_size = sizes[i].natural_size;
+          else
+            col_size = sizes[i].minimum_size;
+
+          gtk_column_view_column_allocate (column, x, col_size);
+          x += col_size;
+        }
 
       g_object_unref (column);
     }
 
-  return width + extra;
+  return x;
 }
 
 static void


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