listview: Simplify allocation
authorBenjamin Otte <otte@redhat.com>
Thu, 2 Mar 2023 20:27:52 +0000 (21:27 +0100)
committerBenjamin Otte <otte.benjamin@googlemail.com>
Sun, 5 Mar 2023 15:23:20 +0000 (15:23 +0000)
With the Tile changes, a lot of stuff does no longer need to be
duplicated between listview and gridview. Move it to ListBase instead.

gtk/gtkgridview.c
gtk/gtklistbase.c
gtk/gtklistbaseprivate.h
gtk/gtklistview.c

index ebc32169cfea04899d53b13692d5151d098d5cdc..93d00a4537f130d9ab7ab4e126c39c9b5734a137 100644 (file)
@@ -624,21 +624,19 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
   GtkListTile *tile, *start;
   GArray *heights;
   int min_row_height, unknown_row_height, row_height, col_min, col_nat;
-  GtkOrientation orientation, opposite_orientation;
+  GtkOrientation orientation;
   GtkScrollablePolicy scroll_policy;
-  GdkRectangle bounds;
-  int x, y;
+  int y;
   guint i;
 
   orientation = gtk_list_base_get_orientation (GTK_LIST_BASE (self));
   scroll_policy = gtk_list_base_get_scroll_policy (GTK_LIST_BASE (self), orientation);
-  opposite_orientation = OPPOSITE_ORIENTATION (orientation);
   min_row_height = ceil ((double) height / GTK_GRID_VIEW_MAX_VISIBLE_ROWS);
 
   /* step 0: exit early if list is empty */
   if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
     {
-      gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
+      gtk_list_base_allocate (GTK_LIST_BASE (self));
       return;
     }
 
@@ -756,19 +754,8 @@ gtk_grid_view_size_allocate (GtkWidget *widget,
         }
     }
 
-  gtk_list_item_manager_get_tile_bounds (self->item_manager, &bounds);
-
-  /* step 4: update the adjustments */
-  gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
-                                    bounds.width,
-                                    bounds.height,
-                                    gtk_widget_get_size (widget, opposite_orientation),
-                                    gtk_widget_get_size (widget, orientation),
-                                    &x, &y);
-
-  gtk_list_base_allocate_children (GTK_LIST_BASE (widget));
-
-  gtk_list_base_allocate_rubberband (GTK_LIST_BASE (widget));
+  /* step 4: allocate the rest */
+  gtk_list_base_allocate (GTK_LIST_BASE (self));
 }
 
 static void
index d4996d74a32ae4a34ba840492ef291b2d9891edf..2008f9a055e20d8555c338b0fc87517a5e45f212 100644 (file)
@@ -1355,7 +1355,7 @@ update_autoscroll (GtkListBase *self,
     remove_autoscroll (self);
 }
 
-/**
+/*
  * gtk_list_base_size_allocate_child:
  * @self: The listbase
  * @child: The child
@@ -1368,7 +1368,7 @@ update_autoscroll (GtkListBase *self,
  * but with the coordinates already offset by the scroll
  * offset.
  **/
-void
+static void
 gtk_list_base_size_allocate_child (GtkListBase *self,
                                    GtkWidget   *child,
                                    int          x,
@@ -1432,7 +1432,7 @@ gtk_list_base_size_allocate_child (GtkListBase *self,
   gtk_widget_size_allocate (child, &child_allocation, -1);
 }
 
-void
+static void
 gtk_list_base_allocate_children (GtkListBase *self)
 {
   GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
@@ -1537,7 +1537,7 @@ gtk_list_base_get_rubberband_coords (GtkListBase  *self,
   return TRUE;
 }
 
-void
+static void
 gtk_list_base_allocate_rubberband (GtkListBase *self)
 {
   GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
@@ -1912,7 +1912,7 @@ gtk_list_base_init_real (GtkListBase      *self,
   gtk_widget_add_controller (GTK_WIDGET (self), controller);
 }
 
-static int
+static void
 gtk_list_base_set_adjustment_values (GtkListBase    *self,
                                      GtkOrientation  orientation,
                                      int             value,
@@ -1940,23 +1940,24 @@ gtk_list_base_set_adjustment_values (GtkListBase    *self,
   g_signal_handlers_unblock_by_func (priv->adjustment[orientation],
                                      gtk_list_base_adjustment_value_changed_cb,
                                      self);
-
-  return value;
 }
 
-void
-gtk_list_base_update_adjustments (GtkListBase *self,
-                                  int          total_across,
-                                  int          total_along,
-                                  int          page_across,
-                                  int          page_along,
-                                  int         *across,
-                                  int         *along)
+static void
+gtk_list_base_update_adjustments (GtkListBase *self)
 {
   GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
+  GdkRectangle bounds;
   int value_along, value_across, size;
+  int page_along, page_across;
   guint pos;
 
+  gtk_list_item_manager_get_tile_bounds (priv->item_manager, &bounds);
+  g_assert (bounds.x == 0);
+  g_assert (bounds.y == 0);
+
+  page_across = gtk_widget_get_size (GTK_WIDGET (self), OPPOSITE_ORIENTATION (priv->orientation));
+  page_along = gtk_widget_get_size (GTK_WIDGET (self), priv->orientation);
+
   pos = gtk_list_item_tracker_get_position (priv->item_manager, priv->anchor);
   if (pos == GTK_INVALID_LIST_POSITION)
     {
@@ -1987,16 +1988,25 @@ gtk_list_base_update_adjustments (GtkListBase *self,
         }
     }
 
-  *across = gtk_list_base_set_adjustment_values (self,
-                                                 OPPOSITE_ORIENTATION (priv->orientation),
-                                                 value_across,
-                                                 total_across,
-                                                 page_across);
-  *along = gtk_list_base_set_adjustment_values (self,
-                                                priv->orientation,
-                                                value_along,
-                                                total_along,
-                                                page_along);
+  gtk_list_base_set_adjustment_values (self,
+                                       OPPOSITE_ORIENTATION (priv->orientation),
+                                       value_across,
+                                       bounds.width,
+                                       page_across);
+  gtk_list_base_set_adjustment_values (self,
+                                       priv->orientation,
+                                       value_along,
+                                       bounds.height,
+                                       page_along);
+}
+
+void
+gtk_list_base_allocate (GtkListBase *self)
+{
+  gtk_list_base_update_adjustments (self);
+
+  gtk_list_base_allocate_children (self);
+  gtk_list_base_allocate_rubberband (self);
 }
 
 GtkScrollablePolicy
index e6047a758c463b3534fd7ad091f755cc5f6ffaeb..a418bec6cd3741c3ae5cf7b01ecec61bae63ef34 100644 (file)
@@ -76,13 +76,6 @@ guint                  gtk_list_base_get_n_items                (GtkListBase
 GtkSelectionModel *    gtk_list_base_get_model                  (GtkListBase            *self);
 gboolean               gtk_list_base_set_model                  (GtkListBase            *self,
                                                                  GtkSelectionModel      *model);
-void                   gtk_list_base_update_adjustments         (GtkListBase            *self,
-                                                                 int                     total_across,
-                                                                 int                     total_along,
-                                                                 int                     page_across,
-                                                                 int                     page_along,
-                                                                 int                    *across,
-                                                                 int                    *along);
 
 guint                  gtk_list_base_get_anchor                 (GtkListBase            *self);
 void                   gtk_list_base_set_anchor                 (GtkListBase            *self,
@@ -107,14 +100,7 @@ gboolean               gtk_list_base_grab_focus_on_item         (GtkListBase
 void                   gtk_list_base_set_enable_rubberband      (GtkListBase            *self,
                                                                  gboolean                enable);
 gboolean               gtk_list_base_get_enable_rubberband      (GtkListBase            *self);
-void                   gtk_list_base_allocate_rubberband        (GtkListBase            *self);
-void                   gtk_list_base_allocate_children          (GtkListBase            *self);
 
-void                   gtk_list_base_size_allocate_child        (GtkListBase            *self,
-                                                                 GtkWidget              *child,
-                                                                 int                     x,
-                                                                 int                     y,
-                                                                 int                     width,
-                                                                 int                     height);
+void                   gtk_list_base_allocate                   (GtkListBase            *self);
 
 #endif /* __GTK_LIST_BASE_PRIVATE_H__ */
index 3c939da806a59c5170e990c8f1d0ad6a67f261f9..408870bccd8fe7ee4887da9599f858a4e740c6d9 100644 (file)
@@ -506,8 +506,7 @@ gtk_list_view_size_allocate (GtkWidget *widget,
   GtkListView *self = GTK_LIST_VIEW (widget);
   GtkListTile *tile;
   GArray *heights;
-  int min, nat, row_height;
-  int x, y;
+  int min, nat, row_height, y;
   GtkOrientation orientation, opposite_orientation;
   GtkScrollablePolicy scroll_policy, opposite_scroll_policy;
 
@@ -519,7 +518,7 @@ gtk_list_view_size_allocate (GtkWidget *widget,
   /* step 0: exit early if list is empty */
   if (gtk_list_item_manager_get_root (self->item_manager) == NULL)
     {
-      gtk_list_base_update_adjustments (GTK_LIST_BASE (self), 0, 0, 0, 0, &x, &y);
+      gtk_list_base_allocate (GTK_LIST_BASE (self));
       return;
     }
 
@@ -570,16 +569,8 @@ gtk_list_view_size_allocate (GtkWidget *widget,
       y += tile->area.height;
     }
 
-  /* step 4: update the adjustments */
-  gtk_list_base_update_adjustments (GTK_LIST_BASE (self),
-                                    self->list_width,
-                                    gtk_list_view_get_list_height (self),
-                                    gtk_widget_get_size (widget, opposite_orientation),
-                                    gtk_widget_get_size (widget, orientation),
-                                    &x, &y);
-
-  gtk_list_base_allocate_children (GTK_LIST_BASE (self));
-  gtk_list_base_allocate_rubberband (GTK_LIST_BASE (self));
+  /* step 4: allocate the rest */
+  gtk_list_base_allocate (GTK_LIST_BASE (self));
 }
 
 static void