[libadwaita/wip/exalm/carousel-fix: 12/13] carousel: Maintain widget order in insert()




commit e75608aa4070e0d792349052c913021daf8a3bf5
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Dec 29 13:12:41 2021 +0500

    carousel: Maintain widget order in insert()
    
    Rename prev_* to next_* to reflect how they are actually used.

 src/adw-carousel.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 3b095d60..6e6bb3ce 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -1246,7 +1246,7 @@ adw_carousel_insert (AdwCarousel *self,
                      int          position)
 {
   ChildInfo *info;
-  GList *prev_link = NULL;
+  GList *next_link = NULL;
 
   g_return_if_fail (ADW_IS_CAROUSEL (self));
   g_return_if_fail (GTK_IS_WIDGET (widget));
@@ -1258,11 +1258,17 @@ adw_carousel_insert (AdwCarousel *self,
   info->adding = TRUE;
 
   if (position >= 0)
-    prev_link = get_nth_link (self, position);
+    next_link = get_nth_link (self, position);
+
+  self->children = g_list_insert_before (self->children, next_link, info);
 
-  self->children = g_list_insert_before (self->children, prev_link, info);
+  if (next_link) {
+    ChildInfo *next_sibling = next_link->data;
 
-  gtk_widget_set_parent (widget, GTK_WIDGET (self));
+    gtk_widget_insert_before (widget, GTK_WIDGET (self), next_sibling->widget);
+  } else {
+    gtk_widget_set_parent (widget, GTK_WIDGET (self));
+  }
 
   gtk_widget_queue_allocate (GTK_WIDGET (self));
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]