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.
This commit is contained in:
Benjamin Otte
2023-03-09 03:34:01 +01:00
parent 12858114a2
commit 334ca12d78
2 changed files with 75 additions and 6 deletions

View File

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

View File

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