listview: Fix clipping for horizontal listviews
authorBenjamin Otte <otte@redhat.com>
Tue, 7 Jun 2022 17:12:17 +0000 (19:12 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 7 Jun 2022 17:21:46 +0000 (19:21 +0200)
Fixes a bug introduced with
commit 39645d32582892bc4fd3bb55ea5d11af860f0efd

gtk/gtklistbase.c

index 81c95d1a4d0c68419a1ca46e98dca99208fc2e69..85827363ced093ffcf94597a5ce02b405a380965 100644 (file)
@@ -1363,34 +1363,20 @@ gtk_list_base_size_allocate_child (GtkListBase *self,
   self_width = gtk_widget_get_width (GTK_WIDGET (self));
   self_height = gtk_widget_get_height (GTK_WIDGET (self));
 
-  if (y + height + GTK_LIST_BASE_CHILD_MAX_OVERDRAW <= 0 ||
-      y - GTK_LIST_BASE_CHILD_MAX_OVERDRAW >= self_height ||
-      x + width + GTK_LIST_BASE_CHILD_MAX_OVERDRAW <= 0 ||
-      x - GTK_LIST_BASE_CHILD_MAX_OVERDRAW >= self_width)
-    {
-      /* child is fully outside the viewport, hide it and don't allocate it */
-      gtk_widget_set_child_visible (child, FALSE);
-      return;
-    }
-
-  gtk_widget_set_child_visible (child, TRUE);
-
   if (gtk_list_base_get_orientation (GTK_LIST_BASE (self)) == GTK_ORIENTATION_VERTICAL)
     {
       if (_gtk_widget_get_direction (GTK_WIDGET (self)) == GTK_TEXT_DIR_LTR)
         {
           child_allocation.x = x;
           child_allocation.y = y;
-          child_allocation.width = width;
-          child_allocation.height = height;
         }
       else
         {
           child_allocation.x = self_width - x - width;
           child_allocation.y = y;
-          child_allocation.width = width;
-          child_allocation.height = height;
         }
+      child_allocation.width = width;
+      child_allocation.height = height;
     }
   else
     {
@@ -1398,18 +1384,32 @@ gtk_list_base_size_allocate_child (GtkListBase *self,
         {
           child_allocation.x = y;
           child_allocation.y = x;
-          child_allocation.width = height;
-          child_allocation.height = width;
         }
       else
         {
           child_allocation.x = self_width - y - height;
           child_allocation.y = x;
-          child_allocation.width = height;
-          child_allocation.height = width;
         }
+      child_allocation.width = height;
+      child_allocation.height = width;
     }
 
+  if (!gdk_rectangle_intersect (&child_allocation,
+                                &(GdkRectangle) {
+                                  - GTK_LIST_BASE_CHILD_MAX_OVERDRAW,
+                                  - GTK_LIST_BASE_CHILD_MAX_OVERDRAW,
+                                  self_width + GTK_LIST_BASE_CHILD_MAX_OVERDRAW,
+                                  self_height + GTK_LIST_BASE_CHILD_MAX_OVERDRAW
+                                },
+                                NULL))
+    {
+      /* child is fully outside the viewport, hide it and don't allocate it */
+      gtk_widget_set_child_visible (child, FALSE);
+      return;
+    }
+
+  gtk_widget_set_child_visible (child, TRUE);
+
   gtk_widget_size_allocate (child, &child_allocation, -1);
 }