From: Benjamin Otte Date: Thu, 9 Mar 2023 02:34:01 +0000 (+0100) Subject: listview: Return an allocation for unallcoated items X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~5^2~30^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=334ca12d788bfbe53bfa16e1c74f7c78a2ad2032;p=gtk4.git listview: Return an allocation for unallcoated items Just get the position right and give them a height of 0px, that should be good enough. If we don't do that, code will think the item doesn't exist, which is not what we want. --- diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index a0eb1acb06..6abbfc55da 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -237,9 +237,42 @@ gtk_grid_view_get_allocation (GtkListBase *base, guint offset; tile = gtk_list_item_manager_get_nth (self->item_manager, pos, &offset); - if (tile == NULL || tile->area.width <= 0 || tile->area.height <= 0) + if (tile == NULL) return FALSE; + if (tile->area.width <= 0 || tile->area.height <= 0) + { + /* item is not allocated yet */ + GtkListTile *other; + + for (other = gtk_rb_tree_node_get_previous (tile); + other; + other = gtk_rb_tree_node_get_previous (other)) + { + if (other->area.width || other->area.height) + { + area->x = other->area.x + other->area.width; + area->y = other->area.y + other->area.height; + break; + } + } + if (other == NULL) + { + for (other = gtk_rb_tree_node_get_next (tile); + other; + other = gtk_rb_tree_node_get_next (other)) + { + if (other->area.width || other->area.height) + { + area->x = other->area.x; + area->y = other->area.y; + break; + } + } + } + return TRUE; + } + *area = tile->area; if (tile->n_items > self->n_columns) diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c index 07f6e15303..6765165791 100644 --- a/gtk/gtklistview.c +++ b/gtk/gtklistview.c @@ -242,12 +242,48 @@ gtk_list_view_get_allocation (GtkListBase *base, return FALSE; *area = tile->area; - if (tile->n_items) - area->height /= tile->n_items; - if (offset) - area->y += offset * area->height; + if (area->width || area->height) + { + if (tile->n_items) + area->height /= tile->n_items; + if (offset) + area->y += offset * area->height; + } + else + { + /* item is not allocated yet */ + GtkListTile *other; - return area->width > 0 && area->height > 0; + for (other = gtk_rb_tree_node_get_previous (tile); + other; + other = gtk_rb_tree_node_get_previous (other)) + { + if (other->area.width || other->area.height) + { + area->x = other->area.x; + area->width = other->area.width; + area->y = other->area.y + other->area.height; + break; + } + } + if (other == NULL) + { + for (other = gtk_rb_tree_node_get_next (tile); + other; + other = gtk_rb_tree_node_get_next (other)) + { + if (other->area.width || other->area.height) + { + area->x = other->area.x; + area->width = other->area.width; + area->y = other->area.y; + break; + } + } + } + } + + return TRUE; } static GtkBitset *