[libhandy/wip/exalm/paginator-animate: 76/78] carousel: Add reveal-duration property



commit 3738a1aee2e7c03fcacf9e490ac1128d500cfd35
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Dec 29 22:12:50 2019 +0500

    carousel: Add reveal-duration property
    
    Expose the HdyCarouselBox one. Add a corresponding test.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-carousel.c    | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/hdy-carousel.h    |  3 +++
 src/hdy-carousel.ui   |  1 +
 tests/test-carousel.c | 27 +++++++++++++++++++
 4 files changed, 104 insertions(+), 1 deletion(-)
---
diff --git a/src/hdy-carousel.c b/src/hdy-carousel.c
index 62bea23e..850a07b3 100644
--- a/src/hdy-carousel.c
+++ b/src/hdy-carousel.c
@@ -96,10 +96,11 @@ enum {
   PROP_SPACING,
   PROP_ANIMATION_DURATION,
   PROP_ALLOW_MOUSE_DRAG,
+  PROP_REVEAL_DURATION,
 
   /* GtkOrientable */
   PROP_ORIENTATION,
-  LAST_PROP = PROP_ALLOW_MOUSE_DRAG + 1,
+  LAST_PROP = PROP_REVEAL_DURATION + 1,
 };
 
 static GParamSpec *props[LAST_PROP];
@@ -224,6 +225,14 @@ notify_spacing_cb (HdyCarousel *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SPACING]);
 }
 
+static void
+notify_reveal_duration_cb (HdyCarousel *self,
+                           GParamSpec  *spec,
+                           GObject     *object)
+{
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_REVEAL_DURATION]);
+}
+
 static void
 animation_stopped_cb (HdyCarousel    *self,
                       HdyCarouselBox *box)
@@ -715,6 +724,10 @@ hdy_carousel_get_property (GObject    *object,
     g_value_set_boolean (value, hdy_carousel_get_allow_mouse_drag (self));
     break;
 
+  case PROP_REVEAL_DURATION:
+    g_value_set_uint (value, hdy_carousel_get_reveal_duration (self));
+    break;
+
   case PROP_ORIENTATION:
     g_value_set_enum (value, self->orientation);
     break;
@@ -761,6 +774,10 @@ hdy_carousel_set_property (GObject      *object,
     hdy_carousel_set_animation_duration (self, g_value_get_uint (value));
     break;
 
+  case PROP_REVEAL_DURATION:
+    hdy_carousel_set_reveal_duration (self, g_value_get_uint (value));
+    break;
+
   case PROP_ALLOW_MOUSE_DRAG:
     hdy_carousel_set_allow_mouse_drag (self, g_value_get_boolean (value));
     break;
@@ -958,6 +975,22 @@ hdy_carousel_class_init (HdyCarouselClass *klass)
                           FALSE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * HdyCarousel:reveal-duration:
+   *
+   * Page reveal duration in milliseconds.
+   *
+   * Since: 1.0
+   */
+  props[PROP_REVEAL_DURATION] =
+    g_param_spec_uint ("reveal-duration",
+                       _("Reveal duration"),
+                       _("Page reveal duration"),
+                       0,
+                       G_MAXUINT,
+                       0,
+                       G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   g_object_class_override_property (object_class,
                                     PROP_ORIENTATION,
                                     "orientation");
@@ -995,6 +1028,7 @@ hdy_carousel_class_init (HdyCarouselClass *klass)
   gtk_widget_class_bind_template_callback (widget_class, notify_n_pages_cb);
   gtk_widget_class_bind_template_callback (widget_class, notify_position_cb);
   gtk_widget_class_bind_template_callback (widget_class, notify_spacing_cb);
+  gtk_widget_class_bind_template_callback (widget_class, notify_reveal_duration_cb);
   gtk_widget_class_bind_template_callback (widget_class, animation_stopped_cb);
   gtk_widget_class_bind_template_callback (widget_class, position_shifted_cb);
 
@@ -1485,3 +1519,41 @@ hdy_carousel_set_allow_mouse_drag (HdyCarousel *self,
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_MOUSE_DRAG]);
 }
+
+/**
+ * hdy_carousel_get_reveal_duration:
+ * @self: a #HdyCarousel
+ *
+ * Gets duration of the animation used when adding or removing pages in
+ * milliseconds.
+ *
+ * Returns: Page reveal duration
+ *
+ * Since: 1.0
+ */
+guint
+hdy_carousel_get_reveal_duration (HdyCarousel *self)
+{
+  g_return_val_if_fail (HDY_IS_CAROUSEL (self), 0);
+
+  return hdy_carousel_box_get_reveal_duration (self->scrolling_box);
+}
+
+/**
+ * hdy_carousel_set_reveal_duration:
+ * @self: a #HdyCarousel
+ * @reveal_duration: the new reveal duration value
+ *
+ * Sets duration of the animation used when adding or removing pages in
+ * milliseconds.
+ *
+ * Since: 1.0
+ */
+void
+hdy_carousel_set_reveal_duration (HdyCarousel *self,
+                                  guint        reveal_duration)
+{
+  g_return_if_fail (HDY_IS_CAROUSEL (self));
+
+  hdy_carousel_box_set_reveal_duration (self->scrolling_box, reveal_duration);
+}
diff --git a/src/hdy-carousel.h b/src/hdy-carousel.h
index f67a31ed..3d235876 100644
--- a/src/hdy-carousel.h
+++ b/src/hdy-carousel.h
@@ -73,4 +73,7 @@ gboolean        hdy_carousel_get_allow_mouse_drag (HdyCarousel *self);
 void            hdy_carousel_set_allow_mouse_drag (HdyCarousel *self,
                                                    gboolean     allow_mouse_drag);
 
+guint           hdy_carousel_get_reveal_duration (HdyCarousel *self);
+void            hdy_carousel_set_reveal_duration (HdyCarousel *self,
+                                                  guint        reveal_duration);
 G_END_DECLS
diff --git a/src/hdy-carousel.ui b/src/hdy-carousel.ui
index 87861ce7..b22fed28 100644
--- a/src/hdy-carousel.ui
+++ b/src/hdy-carousel.ui
@@ -20,6 +20,7 @@
             <signal name="notify::n-pages" handler="notify_n_pages_cb" swapped="true"/>
             <signal name="notify::position" handler="notify_position_cb" swapped="true"/>
             <signal name="notify::spacing" handler="notify_spacing_cb" swapped="true"/>
+            <signal name="notify::reveal-duration" handler="notify_reveal_duration_cb" swapped="true"/>
             <signal name="animation-stopped" handler="animation_stopped_cb" swapped="true"/>
             <signal name="position-shifted" handler="position_shifted_cb" swapped="true"/>
           </object>
diff --git a/tests/test-carousel.c b/tests/test-carousel.c
index 84166821..9269fcca 100644
--- a/tests/test-carousel.c
+++ b/tests/test-carousel.c
@@ -284,6 +284,32 @@ test_hdy_carousel_allow_mouse_drag (void)
   g_assert_cmpint (notified, ==, 2);
 }
 
+static void
+test_hdy_carousel_reveal_duration (void)
+{
+  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  guint duration;
+
+  notified = 0;
+  g_signal_connect (carousel, "notify::reveal-duration", G_CALLBACK (notify_cb), NULL);
+
+  /* Accessors */
+  g_assert_cmpuint (hdy_carousel_get_reveal_duration (carousel), ==, 0);
+  hdy_carousel_set_reveal_duration (carousel, 200);
+  g_assert_cmpuint (hdy_carousel_get_reveal_duration (carousel), ==, 200);
+  g_assert_cmpint (notified, ==, 1);
+
+  /* Property */
+  g_object_set (carousel, "reveal-duration", 500, NULL);
+  g_object_get (carousel, "reveal-duration", &duration, NULL);
+  g_assert_cmpuint (duration, ==, 500);
+  g_assert_cmpint (notified, ==, 2);
+
+  /* Setting the same value should not notify */
+  hdy_carousel_set_reveal_duration (carousel, 500);
+  g_assert_cmpint (notified, ==, 2);
+}
+
 gint
 main (gint argc,
       gchar *argv[])
@@ -299,5 +325,6 @@ main (gint argc,
   g_test_add_func("/Handy/Carousel/spacing", test_hdy_carousel_spacing);
   g_test_add_func("/Handy/Carousel/animation_duration", test_hdy_carousel_animation_duration);
   g_test_add_func("/Handy/Carousel/allow_mouse_drag", test_hdy_carousel_allow_mouse_drag);
+  g_test_add_func("/Handy/Carousel/reveal_duration", test_hdy_carousel_reveal_duration);
   return g_test_run();
 }


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