diff options
author | Benjamin Otte <otte@redhat.com> | 2019-10-22 04:59:34 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-30 19:26:46 -0400 |
commit | c092d0a616af80f4d09816cbcc234c735a913a77 (patch) | |
tree | a2235338b2069f6ec1884e76c9e83b97a6a80ed5 /gtk/gtkgridview.c | |
parent | ea390a4a735c8437802eb568205b6156e89f4db9 (diff) | |
download | gtk+-c092d0a616af80f4d09816cbcc234c735a913a77.tar.gz |
gridview: Simplify allocation code
It doesn't fix the bug I'm after, but it looks a lot better.
Diffstat (limited to 'gtk/gtkgridview.c')
-rw-r--r-- | gtk/gtkgridview.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index 1800f12df5..c5c6418f73 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -1028,44 +1028,58 @@ 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 (cell->parent.widget) { - if (i == 0) - { - y += row_height; - row_height = cell->size; - } + 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; + i++; + if (i >= self->n_columns) + { + y += row_height; + i -= self->n_columns; + row_height = 0; + } } else { i += cell->parent.n_items; - if (i > self->n_columns) + /* skip remaining row if we didn't start one */ + if (i > cell->parent.n_items && i >= self->n_columns) { i -= self->n_columns; y += row_height; - row_height = cell->size; + row_height = 0; + } - 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; - } + row_height += cell->size; + + /* skip rows that are completely contained by this cell */ + if (i >= self->n_columns) + { + guint unknown_rows, unknown_height; + + unknown_rows = i / self->n_columns; + unknown_height = unknown_rows * self->unknown_row_height; + row_height -= unknown_height; + y += unknown_height; + i %= self->n_columns; + g_assert (row_height >= 0); } } } |