listview: Return an allocation for unallcoated items
authorBenjamin Otte <otte@redhat.com>
Thu, 9 Mar 2023 02:34:01 +0000 (03:34 +0100)
committerBenjamin Otte <otte@redhat.com>
Fri, 10 Mar 2023 04:26:28 +0000 (05:26 +0100)
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.

gtk/gtkgridview.c
gtk/gtklistview.c

index a0eb1acb06930bc604c0de385c35a08456be2af7..6abbfc55dadb03fa9bf672062f24c5df908bedc2 100644 (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)
index 07f6e15303d5adb785e8d921875574ccb2c17310..6765165791d7eb939d21f411217d55e471fa42cd 100644 (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 *