[libhandy] carousel: Add allow-long-swipes property



commit b90b5120c5e9e3f5a3b0d228bd7ddb24f053289a
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Jul 12 20:00:43 2020 +0500

    carousel: Add allow-long-swipes property
    
    Expose the HdySwipeTracker property, as it's relevant here.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 debian/libhandy-1-0.symbols |  2 ++
 src/hdy-carousel.c          | 69 +++++++++++++++++++++++++++++++++++++++++++++
 src/hdy-carousel.h          |  6 ++++
 tests/test-carousel.c       | 27 ++++++++++++++++++
 4 files changed, 104 insertions(+)
---
diff --git a/debian/libhandy-1-0.symbols b/debian/libhandy-1-0.symbols
index 0c8aebb2..cab1fa7e 100644
--- a/debian/libhandy-1-0.symbols
+++ b/debian/libhandy-1-0.symbols
@@ -30,6 +30,7 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
  hdy_avatar_set_show_initials@LIBHANDY_1_0 0.80.0
  hdy_avatar_set_size@LIBHANDY_1_0 0.80.0
  hdy_avatar_set_text@LIBHANDY_1_0 0.80.0
+ hdy_carousel_get_allow_long_swipes@LIBHANDY_1_0 1.1.0
  hdy_carousel_get_allow_mouse_drag@LIBHANDY_1_0 0.80.0
  hdy_carousel_get_animation_duration@LIBHANDY_1_0 0.80.0
  hdy_carousel_get_interactive@LIBHANDY_1_0 0.80.0
@@ -52,6 +53,7 @@ libhandy-1.so.0 libhandy-1-0 #MINVER#
  hdy_carousel_reorder@LIBHANDY_1_0 0.80.0
  hdy_carousel_scroll_to@LIBHANDY_1_0 0.80.0
  hdy_carousel_scroll_to_full@LIBHANDY_1_0 0.80.0
+ hdy_carousel_set_allow_long_swipes@LIBHANDY_1_0 1.1.0
  hdy_carousel_set_allow_mouse_drag@LIBHANDY_1_0 0.80.0
  hdy_carousel_set_animation_duration@LIBHANDY_1_0 0.80.0
  hdy_carousel_set_interactive@LIBHANDY_1_0 0.80.0
diff --git a/src/hdy-carousel.c b/src/hdy-carousel.c
index 7d8db553..740e21e3 100644
--- a/src/hdy-carousel.c
+++ b/src/hdy-carousel.c
@@ -64,6 +64,7 @@ enum {
   PROP_SPACING,
   PROP_ANIMATION_DURATION,
   PROP_ALLOW_MOUSE_DRAG,
+  PROP_ALLOW_LONG_SWIPES,
   PROP_REVEAL_DURATION,
 
   /* GtkOrientable */
@@ -473,6 +474,10 @@ hdy_carousel_get_property (GObject    *object,
     g_value_set_boolean (value, hdy_carousel_get_allow_mouse_drag (self));
     break;
 
+  case PROP_ALLOW_LONG_SWIPES:
+    g_value_set_boolean (value, hdy_carousel_get_allow_long_swipes (self));
+    break;
+
   case PROP_REVEAL_DURATION:
     g_value_set_uint (value, hdy_carousel_get_reveal_duration (self));
     break;
@@ -519,6 +524,10 @@ hdy_carousel_set_property (GObject      *object,
     hdy_carousel_set_allow_mouse_drag (self, g_value_get_boolean (value));
     break;
 
+  case PROP_ALLOW_LONG_SWIPES:
+    hdy_carousel_set_allow_long_swipes (self, g_value_get_boolean (value));
+    break;
+
   case PROP_ORIENTATION:
     {
       GtkOrientation orientation = g_value_get_enum (value);
@@ -656,6 +665,21 @@ hdy_carousel_class_init (HdyCarouselClass *klass)
                           TRUE,
                           G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
 
+  /**
+   * HdyCarousel:allow-long-swipes:
+   *
+   * Whether to allow swiping for more than one page at a time. If the value is
+   * %FALSE, each swipe can only move to the adjacent pages.
+   *
+   * Since: 1.1
+   */
+  props[PROP_ALLOW_LONG_SWIPES] =
+    g_param_spec_boolean ("allow-long-swipes",
+                          _("Allow long swipes"),
+                          _("Whether to allow swiping for more than one page at a time"),
+                          FALSE,
+                          G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
   /**
    * HdyCarousel:reveal-duration:
    *
@@ -1060,6 +1084,51 @@ hdy_carousel_set_allow_mouse_drag (HdyCarousel *self,
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_MOUSE_DRAG]);
 }
 
+/**
+ * hdy_carousel_get_allow_long_swipes:
+ * @self: a #HdyCarousel
+ *
+ * Whether to allow swiping for more than one page at a time. If the value is
+ * %FALSE, each swipe can only move to the adjacent pages.
+ *
+ * Returns: %TRUE if long swipes are allowed, %FALSE otherwise
+ *
+ * Since: 1.1
+ */
+gboolean
+hdy_carousel_get_allow_long_swipes (HdyCarousel *self)
+{
+  g_return_val_if_fail (HDY_IS_CAROUSEL (self), FALSE);
+
+  return hdy_swipe_tracker_get_allow_long_swipes (self->tracker);
+}
+
+/**
+ * hdy_carousel_set_allow_long_swipes:
+ * @self: a #HdyCarousel
+ * @allow_long_swipes: whether to allow long swipes
+ *
+ * Sets whether to allow swiping for more than one page at a time. If the value
+ * is %FALSE, each swipe can only move to the adjacent pages.
+ *
+ * Since: 1.1
+ */
+void
+hdy_carousel_set_allow_long_swipes (HdyCarousel *self,
+                                    gboolean     allow_long_swipes)
+{
+  g_return_if_fail (HDY_IS_CAROUSEL (self));
+
+  allow_long_swipes = !!allow_long_swipes;
+
+  if (hdy_swipe_tracker_get_allow_long_swipes (self->tracker) == allow_long_swipes)
+    return;
+
+  hdy_swipe_tracker_set_allow_long_swipes (self->tracker, allow_long_swipes);
+
+  g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_LONG_SWIPES]);
+}
+
 /**
  * hdy_carousel_get_reveal_duration:
  * @self: a #HdyCarousel
diff --git a/src/hdy-carousel.h b/src/hdy-carousel.h
index 4318b653..72aee56f 100644
--- a/src/hdy-carousel.h
+++ b/src/hdy-carousel.h
@@ -73,6 +73,12 @@ HDY_AVAILABLE_IN_ALL
 void            hdy_carousel_set_allow_mouse_drag (HdyCarousel *self,
                                                    gboolean     allow_mouse_drag);
 
+HDY_AVAILABLE_IN_1_1
+gboolean        hdy_carousel_get_allow_long_swipes (HdyCarousel *self);
+HDY_AVAILABLE_IN_1_1
+void            hdy_carousel_set_allow_long_swipes (HdyCarousel *self,
+                                                    gboolean     allow_long_swipes);
+
 HDY_AVAILABLE_IN_ALL
 guint           hdy_carousel_get_reveal_duration (HdyCarousel *self);
 HDY_AVAILABLE_IN_ALL
diff --git a/tests/test-carousel.c b/tests/test-carousel.c
index 45b2fec9..c9605857 100644
--- a/tests/test-carousel.c
+++ b/tests/test-carousel.c
@@ -202,6 +202,32 @@ test_hdy_carousel_allow_mouse_drag (void)
   g_assert_cmpint (notified, ==, 2);
 }
 
+static void
+test_hdy_carousel_allow_long_swipes (void)
+{
+  HdyCarousel *carousel = HDY_CAROUSEL (hdy_carousel_new ());
+  gboolean allow_long_swipes;
+
+  notified = 0;
+  g_signal_connect (carousel, "notify::allow-long-swipes", G_CALLBACK (notify_cb), NULL);
+
+  /* Accessors */
+  g_assert_false (hdy_carousel_get_allow_long_swipes (carousel));
+  hdy_carousel_set_allow_long_swipes (carousel, TRUE);
+  g_assert_true (hdy_carousel_get_allow_long_swipes (carousel));
+  g_assert_cmpint (notified, ==, 1);
+
+  /* Property */
+  g_object_set (carousel, "allow-long-swipes", FALSE, NULL);
+  g_object_get (carousel, "allow-long-swipes", &allow_long_swipes, NULL);
+  g_assert_false (allow_long_swipes);
+  g_assert_cmpint (notified, ==, 2);
+
+  /* Setting the same value should not notify */
+  hdy_carousel_set_allow_long_swipes (carousel, FALSE);
+  g_assert_cmpint (notified, ==, 2);
+}
+
 static void
 test_hdy_carousel_reveal_duration (void)
 {
@@ -241,6 +267,7 @@ 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/allow_long_swipes", test_hdy_carousel_allow_long_swipes);
   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]