[libhandy/wip/exalm/paginator-animate: 40/41] carousel-box: Track child additions and removals



commit e019d18134767412ea5b54d5e67fc7cf4997ba31
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Dec 24 16:59:35 2019 +0500

    carousel-box: Track child additions and removals
    
    This is needed so that indicators can show an animation.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-carousel-box.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
---
diff --git a/src/hdy-carousel-box.c b/src/hdy-carousel-box.c
index 225fd7ef..33c5f7b1 100644
--- a/src/hdy-carousel-box.c
+++ b/src/hdy-carousel-box.c
@@ -96,6 +96,8 @@ static GParamSpec *props[LAST_PROP];
 enum {
   SIGNAL_ANIMATION_STOPPED,
   SIGNAL_POSITION_SHIFTED,
+  SIGNAL_PAGE_ADDED,
+  SIGNAL_PAGE_REMOVED,
   SIGNAL_LAST_SIGNAL,
 };
 static guint signals[SIGNAL_LAST_SIGNAL];
@@ -930,11 +932,14 @@ hdy_carousel_box_remove (GtkContainer *container,
 {
   HdyCarouselBox *self = HDY_CAROUSEL_BOX (container);
   HdyCarouselBoxChildInfo *info;
+  gint index;
 
   info = find_child_info (self, widget);
   if (!info)
     return;
 
+  index = g_list_index (self->children, info);
+
   info->removing = TRUE;
 
   gtk_widget_unparent (widget);
@@ -946,6 +951,8 @@ hdy_carousel_box_remove (GtkContainer *container,
 
   animate_child (self, info, 0, self->reveal_duration);
 
+  g_signal_emit (self, signals[SIGNAL_PAGE_REMOVED], 0, index);
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_N_PAGES]);
 }
 
@@ -1182,6 +1189,44 @@ hdy_carousel_box_class_init (HdyCarouselBoxClass *klass)
                   G_TYPE_NONE,
                   1,
                   G_TYPE_DOUBLE);
+
+  /**
+   * HdyCarouselBox::page-added:
+   * @self: The #HdyCarouselBox instance
+   * @index: The index of the new page
+   *
+   * This signal is emitted when a page has been added at @index.
+   *
+   * Since: 1.0
+   */
+  signals[SIGNAL_PAGE_ADDED] =
+    g_signal_new ("page-added",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE,
+                  1,
+                  G_TYPE_UINT);
+
+  /**
+   * HdyCarouselBox::page-removed:
+   * @self: The #HdyCarouselBox instance
+   * @index: The index of the new page
+   *
+   * This signal is emitted when a page has been removed at @index.
+   *
+   * Since: 1.0
+   */
+  signals[SIGNAL_PAGE_REMOVED] =
+    g_signal_new ("page-removed",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST,
+                  0,
+                  NULL, NULL, NULL,
+                  G_TYPE_NONE,
+                  1,
+                  G_TYPE_UINT);
 }
 
 static void
@@ -1230,6 +1275,7 @@ hdy_carousel_box_insert (HdyCarouselBox *self,
 {
   HdyCarouselBoxChildInfo *info;
   GList *prev_link;
+  gint index;
 
   g_return_if_fail (HDY_IS_CAROUSEL_BOX (self));
   g_return_if_fail (GTK_IS_WIDGET (widget));
@@ -1257,6 +1303,9 @@ hdy_carousel_box_insert (HdyCarouselBox *self,
 
   invalidate_drawing_cache (self);
 
+  index = g_list_index (self->children, info);
+  g_signal_emit (self, signals[SIGNAL_PAGE_ADDED], 0, index);
+
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_N_PAGES]);
 }
 


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