From dda24956a14bf8180a5c297cda3f3f514aa5f847 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 21 May 2023 07:45:17 -0400 Subject: [PATCH] gridview: Add a function to split tiles Break this part of size_allocate out as a separate function. Future commits will rewrite size_allocate to make use of it. Making this a standalone function taking just a listitemmanager and n_columns as arguments will make it easy to write tests for it. --- gtk/gtkgridview.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 7bf11e235b..6ccbbf18a2 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -767,6 +767,48 @@ gtk_grid_view_measure (GtkWidget *widget, gtk_grid_view_measure_across (widget, for_size, minimum, natural); } +static void +gtk_grid_view_split_tiles_by_columns (GtkListItemManager *items, + guint n_columns) +{ + GtkListTile *tile; + + for (tile = gtk_list_item_manager_get_first (items); + tile != NULL; + tile = gtk_rb_tree_node_get_next (tile)) + { + if (tile->n_items > 1) + { + guint pos, col; + guint remaining; + + pos = gtk_list_tile_get_position (items, tile); + col = gtk_grid_view_get_column_for_position (items, n_columns, pos); + + if (col > 0) + { + /* Determine if the first row needs to be split off */ + remaining = n_columns - col; + if (remaining > 0 && tile->n_items > remaining) + gtk_list_tile_split (items, tile, remaining); + + continue; + } + + pos += tile->n_items - 1; + col = gtk_grid_view_get_column_for_position (items, n_columns, pos); + + if (col < n_columns - 1) + { + /* Determine if the last row needs to be split off */ + remaining = n_columns - (col - 1); + if (remaining > 0 && col + 1 < tile->n_items) + tile = gtk_list_tile_split (items, tile, tile->n_items - (col + 1)); + } + } + } +} + static void gtk_grid_view_size_allocate (GtkWidget *widget, int width,