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.
This commit is contained in:
Matthias Clasen
2023-05-21 07:45:17 -04:00
parent 243914ff6a
commit dda24956a1

View File

@@ -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,