[gtk/wip/otte/listview: 1/44] gridview: Simplify allocation code



commit f9860e27c72a9ae3696a8eb66a137bc16bdf6615
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 22 04:59:34 2019 +0200

    gridview: Simplify allocation code
    
    It doesn't fix the bug I'm after, but it looks a lot better.

 gtk/gtkgridview.c | 43 ++++++++++++++++++++-----------------------
 1 file changed, 20 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index 01fa8fa740..231b4ff378 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -1022,45 +1022,42 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
   x = - gtk_grid_view_update_adjustment (self, opposite_orientation);
   y = - gtk_grid_view_update_adjustment (self, self->orientation);
 
+  /* step 5: run the size_allocate loop */
+  x = -x;
+  y = -y;
   i = 0;
   row_height = 0;
+
   for (cell = gtk_list_item_manager_get_first (self->item_manager);
        cell != NULL;
        cell = gtk_rb_tree_node_get_next (cell))
     {
+      if (i == 0)
+        row_height = cell->size;
+
       if (cell->parent.widget)
         {
-          if (i == 0)
-            {
-              y += row_height;
-              row_height = cell->size;
-            }
           gtk_grid_view_size_allocate_child (self,
                                              cell->parent.widget,
                                              x + ceil (self->column_width * i),
                                              y,
                                              ceil (self->column_width * (i + 1)) - ceil (self->column_width 
* i),
                                              row_height);
-          i = (i + 1) % self->n_columns;
         }
-      else
+      
+      i += cell->parent.n_items;
+      if (i > self->n_columns)
         {
-          i += cell->parent.n_items;
-          if (i > self->n_columns)
-            {
-              i -= self->n_columns;
-              y += row_height;
-              row_height = cell->size;
-
-              if (i > self->n_columns)
-                {
-                  guint unknown_rows = (i - 1) / self->n_columns;
-                  int unknown_height = unknown_rows * self->unknown_row_height;
-                  row_height -= unknown_height;
-                  y += unknown_height;
-                  i %= self->n_columns;
-                }
-            }
+          guint unknown_rows = i / self->n_columns;
+          int unknown_height = unknown_rows * self->unknown_row_height;
+          row_height -= unknown_height;
+          y += unknown_height;
+          i %= self->n_columns;
+        }
+      else if (i == self->n_columns)
+        {
+          y += row_height;
+          i = 0;
         }
     }
 }


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