[gtk/columnview-layout] columnviewlayout: Handle for_size propertly



commit 40f6a9d830cbbf40b6c7d0e53054ddb24cd8688d
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jun 5 11:34:51 2020 -0400

    columnviewlayout: Handle for_size propertly
    
    When we are given a for_size as width for the whole
    column view, we need to distribute it over the columns
    as gtk_column_view_allocate_columns would, in order
    to find out which for_size to give to each cell.
    
    This is a bit recursive, but works. Since we are
    doing this recursion for every row, we should consider
    adding a cache for those distributed widths.

 gtk/gtkcolumnviewlayout.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkcolumnviewlayout.c b/gtk/gtkcolumnviewlayout.c
index 44d99df673..1b56a3b6ff 100644
--- a/gtk/gtkcolumnviewlayout.c
+++ b/gtk/gtkcolumnviewlayout.c
@@ -47,10 +47,19 @@ gtk_column_view_layout_measure_along (GtkColumnViewLayout *self,
 {
   GtkOrientation orientation = GTK_ORIENTATION_VERTICAL;
   GtkWidget *child;
+  guint i, n;
+  GtkRequestedSize *sizes = NULL;
 
-  for (child = _gtk_widget_get_first_child (widget);
+  if (for_size > -1)
+    {
+      n = g_list_model_get_n_items (gtk_column_view_get_columns (self->view));
+      sizes = g_newa (GtkRequestedSize, n);
+      gtk_column_view_distribute_width (self->view, for_size, sizes);
+    }
+
+  for (child = _gtk_widget_get_first_child (widget), i = 0;
        child != NULL;
-       child = _gtk_widget_get_next_sibling (child))
+       child = _gtk_widget_get_next_sibling (child), i++)
     {
       int child_min = 0;
       int child_nat = 0;
@@ -60,7 +69,8 @@ gtk_column_view_layout_measure_along (GtkColumnViewLayout *self,
       if (!gtk_widget_should_layout (child))
         continue;
 
-      gtk_widget_measure (child, orientation, for_size,
+      gtk_widget_measure (child, orientation,
+                          for_size > -1 ? sizes[i].minimum_size : -1,
                           &child_min, &child_nat,
                           &child_min_baseline, &child_nat_baseline);
 


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