[libhandy/wip/exalm/paginator-animate: 22/41] swipeable: Add gesture state getters



commit e60a39eb186de6ee881102b62b389ab7deba5c1d
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Thu Dec 26 14:04:11 2019 +0500

    swipeable: Add gesture state getters
    
    This will allow lazy access to the state in the next commit.
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-carousel.c              |  95 +++++++++++++++---
 src/hdy-deck.c                  |  30 ++++++
 src/hdy-leaflet.c               |  30 ++++++
 src/hdy-stackable-box-private.h |   6 ++
 src/hdy-stackable-box.c         | 216 ++++++++++++++++++++++++----------------
 src/hdy-swipeable-private.h     |   9 ++
 src/hdy-swipeable.c             | 147 +++++++++++++++++++++++++++
 src/hdy-swipeable.h             |  14 +++
 8 files changed, 448 insertions(+), 99 deletions(-)
---
diff --git a/src/hdy-carousel.c b/src/hdy-carousel.c
index 0b841806..9c6d63d9 100644
--- a/src/hdy-carousel.c
+++ b/src/hdy-carousel.c
@@ -129,25 +129,19 @@ hdy_carousel_begin_swipe (HdySwipeable           *swipeable,
                           gboolean                direct)
 {
   HdyCarousel *self = HDY_CAROUSEL (swipeable);
-  gdouble distance, position, closest_point;
-  guint i, n_pages;
-  gdouble *points;
+  gdouble distance, progress, cancel_progress;
+  gint n_snap_points;
+  gdouble *snap_points;
 
   hdy_carousel_box_stop_animation (self->scrolling_box);
 
-  distance = hdy_carousel_box_get_distance (self->scrolling_box);
-  g_object_get (self->scrolling_box,
-                "position", &position,
-                "n-pages", &n_pages,
-                NULL);
-  closest_point = CLAMP (round (position), 0, n_pages - 1);
-
-  points = g_new (gdouble, n_pages);
-  for (i = 0; i < n_pages; i++)
-    points[i] = i;
+  distance = hdy_swipeable_get_distance (swipeable);
+  snap_points = hdy_swipeable_get_snap_points (swipeable, &n_snap_points);
+  progress = hdy_swipeable_get_progress (swipeable);
+  cancel_progress = hdy_swipeable_get_cancel_progress (swipeable);
 
-  hdy_swipe_tracker_confirm_swipe (self->tracker, distance, points, n_pages,
-                                   position, closest_point);
+  hdy_swipe_tracker_confirm_swipe (self->tracker, distance, snap_points,
+                                   n_snap_points, progress, cancel_progress);
 }
 
 static void
@@ -174,6 +168,72 @@ hdy_carousel_end_swipe (HdySwipeable *swipeable,
   hdy_carousel_box_animate (self->scrolling_box, to, duration);
 }
 
+static gdouble
+hdy_carousel_get_distance (HdySwipeable *swipeable)
+{
+  HdyCarousel *self = HDY_CAROUSEL (swipeable);
+
+  return hdy_carousel_box_get_distance (self->scrolling_box);
+}
+
+static void
+hdy_carousel_get_range (HdySwipeable *swipeable,
+                        gdouble      *lower,
+                        gdouble      *upper)
+{
+  HdyCarousel *self = HDY_CAROUSEL (swipeable);
+
+  if (lower)
+    *lower = 0;
+
+  if (upper)
+    *upper = hdy_carousel_get_n_pages (self) - 1;
+}
+
+static gdouble *
+hdy_carousel_get_snap_points (HdySwipeable *swipeable,
+                              gint         *n_snap_points)
+{
+  HdyCarousel *self = HDY_CAROUSEL (swipeable);
+  guint i, n_pages;
+  gdouble *points;
+
+  n_pages = hdy_carousel_get_n_pages (self);
+
+  points = g_new (gdouble, n_pages);
+  for (i = 0; i < n_pages; i++)
+    points[i] = i;
+
+  if (n_snap_points)
+    *n_snap_points = n_pages;
+
+  return points;
+}
+
+static gdouble
+hdy_carousel_get_progress (HdySwipeable *swipeable)
+{
+  HdyCarousel *self = HDY_CAROUSEL (swipeable);
+
+  return hdy_carousel_get_position (self);
+}
+
+static gdouble
+hdy_carousel_get_cancel_progress (HdySwipeable *swipeable)
+{
+  gdouble position;
+  guint n_pages;
+
+  HdyCarousel *self = HDY_CAROUSEL (swipeable);
+
+  g_object_get (self->scrolling_box,
+                "position", &position,
+                "n-pages", &n_pages,
+                NULL);
+
+  return CLAMP (round (position), 0, n_pages - 1);
+}
+
 static void
 notify_n_pages_cb (HdyCarousel *self,
                    GParamSpec  *spec,
@@ -758,6 +818,11 @@ hdy_carousel_swipeable_init (HdySwipeableInterface *iface)
   iface->begin_swipe = hdy_carousel_begin_swipe;
   iface->update_swipe = hdy_carousel_update_swipe;
   iface->end_swipe = hdy_carousel_end_swipe;
+  iface->get_distance = hdy_carousel_get_distance;
+  iface->get_range = hdy_carousel_get_range;
+  iface->get_snap_points = hdy_carousel_get_snap_points;
+  iface->get_progress = hdy_carousel_get_progress;
+  iface->get_cancel_progress = hdy_carousel_get_cancel_progress;
 }
 
 static void
diff --git a/src/hdy-deck.c b/src/hdy-deck.c
index b2a0f997..ef435b2a 100644
--- a/src/hdy-deck.c
+++ b/src/hdy-deck.c
@@ -780,6 +780,32 @@ hdy_deck_end_swipe (HdySwipeable *swipeable,
   hdy_stackable_box_end_swipe (HDY_GET_HELPER (swipeable), duration, to);
 }
 
+static gdouble
+hdy_deck_get_distance (HdySwipeable *swipeable)
+{
+  return hdy_stackable_box_get_distance (HDY_GET_HELPER (swipeable));
+}
+
+static void
+hdy_deck_get_range (HdySwipeable *swipeable,
+                       gdouble      *lower,
+                       gdouble      *upper)
+{
+  hdy_stackable_box_get_range (HDY_GET_HELPER (swipeable), lower, upper);
+}
+
+static gdouble
+hdy_deck_get_progress (HdySwipeable *swipeable)
+{
+  return hdy_stackable_box_get_progress (HDY_GET_HELPER (swipeable));
+}
+
+static gdouble
+hdy_deck_get_cancel_progress (HdySwipeable *swipeable)
+{
+  return hdy_stackable_box_get_cancel_progress (HDY_GET_HELPER (swipeable));
+}
+
 static gboolean
 captured_event_cb (HdyDeck  *self,
                    GdkEvent *event)
@@ -1049,4 +1075,8 @@ hdy_deck_swipeable_init (HdySwipeableInterface *iface)
   iface->begin_swipe = hdy_deck_begin_swipe;
   iface->update_swipe = hdy_deck_update_swipe;
   iface->end_swipe = hdy_deck_end_swipe;
+  iface->get_distance = hdy_deck_get_distance;
+  iface->get_range = hdy_deck_get_range;
+  iface->get_progress = hdy_deck_get_progress;
+  iface->get_cancel_progress = hdy_deck_get_cancel_progress;
 }
diff --git a/src/hdy-leaflet.c b/src/hdy-leaflet.c
index 3e1b62f2..f8e2729b 100644
--- a/src/hdy-leaflet.c
+++ b/src/hdy-leaflet.c
@@ -852,6 +852,32 @@ hdy_leaflet_end_swipe (HdySwipeable    *swipeable,
   hdy_stackable_box_end_swipe (HDY_GET_HELPER (swipeable), duration, to);
 }
 
+static gdouble
+hdy_leaflet_get_distance (HdySwipeable *swipeable)
+{
+  return hdy_stackable_box_get_distance (HDY_GET_HELPER (swipeable));
+}
+
+static void
+hdy_leaflet_get_range (HdySwipeable *swipeable,
+                       gdouble      *lower,
+                       gdouble      *upper)
+{
+  hdy_stackable_box_get_range (HDY_GET_HELPER (swipeable), lower, upper);
+}
+
+static gdouble
+hdy_leaflet_get_progress (HdySwipeable *swipeable)
+{
+  return hdy_stackable_box_get_progress (HDY_GET_HELPER (swipeable));
+}
+
+static gdouble
+hdy_leaflet_get_cancel_progress (HdySwipeable *swipeable)
+{
+  return hdy_stackable_box_get_cancel_progress (HDY_GET_HELPER (swipeable));
+}
+
 static gboolean
 captured_event_cb (HdyLeaflet *self,
                    GdkEvent   *event)
@@ -1153,4 +1179,8 @@ hdy_leaflet_swipeable_init (HdySwipeableInterface *iface)
   iface->begin_swipe = hdy_leaflet_begin_swipe;
   iface->update_swipe = hdy_leaflet_update_swipe;
   iface->end_swipe = hdy_leaflet_end_swipe;
+  iface->get_distance = hdy_leaflet_get_distance;
+  iface->get_range = hdy_leaflet_get_range;
+  iface->get_progress = hdy_leaflet_get_progress;
+  iface->get_cancel_progress = hdy_leaflet_get_cancel_progress;
 }
diff --git a/src/hdy-stackable-box-private.h b/src/hdy-stackable-box-private.h
index 45c37909..ac403713 100644
--- a/src/hdy-stackable-box-private.h
+++ b/src/hdy-stackable-box-private.h
@@ -96,6 +96,12 @@ void             hdy_stackable_box_update_swipe (HdyStackableBox *self,
 void             hdy_stackable_box_end_swipe (HdyStackableBox *self,
                                               gint64           duration,
                                               gdouble          to);
+gdouble          hdy_stackable_box_get_distance (HdyStackableBox *self);
+void             hdy_stackable_box_get_range (HdyStackableBox *self,
+                                              gdouble         *lower,
+                                              gdouble         *upper);
+gdouble          hdy_stackable_box_get_progress (HdyStackableBox *self);
+gdouble          hdy_stackable_box_get_cancel_progress (HdyStackableBox *self);
 
 void             hdy_stackable_box_add (HdyStackableBox *self,
                                         GtkWidget       *widget);
diff --git a/src/hdy-stackable-box.c b/src/hdy-stackable-box.c
index c58ad741..cecf4f38 100644
--- a/src/hdy-stackable-box.c
+++ b/src/hdy-stackable-box.c
@@ -178,6 +178,8 @@ struct _HdyStackableBox
 
     HdyStackableBoxTransitionType active_type;
     GtkPanDirection active_direction;
+    gboolean is_direct_swipe;
+    gint swipe_direction;
   } child_transition;
 
   HdyShadowHelper *shadow_helper;
@@ -402,6 +404,7 @@ hdy_stackable_box_child_progress_updated (HdyStackableBox *self)
     }
 
     gtk_widget_queue_allocate (GTK_WIDGET (self->container));
+    self->child_transition.swipe_direction = 0;
     hdy_shadow_helper_clear_cache (self->shadow_helper);
   }
 }
@@ -478,6 +481,7 @@ hdy_stackable_box_stop_child_transition (HdyStackableBox *self)
     self->last_visible_child = NULL;
   }
 
+  self->child_transition.swipe_direction = 0;
   hdy_shadow_helper_clear_cache (self->shadow_helper);
 
   /* Move the bin window back in place as a child transition might have moved it. */
@@ -3013,6 +3017,109 @@ hdy_stackable_box_unmap (HdyStackableBox *self)
   GTK_WIDGET_CLASS (self->klass)->unmap (GTK_WIDGET (self->container));
 }
 
+gdouble
+hdy_stackable_box_get_distance (HdyStackableBox *self)
+{
+  if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
+    return gtk_widget_get_allocated_width (GTK_WIDGET (self->container));
+  else
+    return gtk_widget_get_allocated_height (GTK_WIDGET (self->container));
+}
+
+static gboolean
+can_swipe_in_direction (HdyStackableBox        *self,
+                        HdyNavigationDirection  direction)
+{
+  switch (direction) {
+  case HDY_NAVIGATION_DIRECTION_BACK:
+    return self->child_transition.can_swipe_back;
+  case HDY_NAVIGATION_DIRECTION_FORWARD:
+    return self->child_transition.can_swipe_forward;
+  default:
+    g_assert_not_reached ();
+  }
+}
+
+void
+hdy_stackable_box_get_range (HdyStackableBox *self,
+                             gdouble         *lower,
+                             gdouble         *upper)
+{
+  if (self->child_transition.tick_id > 0 ||
+      self->child_transition.is_gesture_active) {
+    gint current_direction;
+    gboolean is_rtl;
+
+    is_rtl = (gtk_widget_get_direction (GTK_WIDGET (self->container)) == GTK_TEXT_DIR_RTL);
+
+    switch (self->child_transition.active_direction) {
+    case GTK_PAN_DIRECTION_UP:
+      current_direction = 1;
+      break;
+    case GTK_PAN_DIRECTION_DOWN:
+      current_direction = -1;
+      break;
+    case GTK_PAN_DIRECTION_LEFT:
+      current_direction = is_rtl ? -1 : 1;
+      break;
+    case GTK_PAN_DIRECTION_RIGHT:
+      current_direction = is_rtl ? 1 : -1;
+      break;
+    default:
+      g_assert_not_reached ();
+    }
+
+    if (lower)
+      *lower = MIN (0, current_direction);
+
+    if (upper)
+      *upper = MAX (0, current_direction);
+  } else {
+    HdyStackableBoxChildInfo *child;
+
+    if ((can_swipe_in_direction (self, self->child_transition.swipe_direction) ||
+         !self->child_transition.is_direct_swipe) && self->folded)
+      child = find_swipeable_child (self, self->child_transition.swipe_direction);
+    else
+      child = NULL;
+
+    if (lower)
+      *lower = MIN (0, child ? self->child_transition.swipe_direction : 0);
+
+    if (upper)
+      *upper = MAX (0, child ? self->child_transition.swipe_direction : 0);
+  }
+}
+
+gdouble
+hdy_stackable_box_get_progress (HdyStackableBox *self)
+{
+  gboolean new_first = FALSE;
+  GList *children;
+
+  if (!self->child_transition.is_gesture_active &&
+      gtk_progress_tracker_get_state (&self->child_transition.tracker) == GTK_PROGRESS_STATE_AFTER)
+    return 0;
+
+  for (children = self->children; children; children = children->next) {
+    if (self->last_visible_child == children->data) {
+      new_first = TRUE;
+
+      break;
+    }
+    if (self->visible_child == children->data)
+      break;
+  }
+
+  return self->child_transition.progress * (new_first ? 1 : -1);
+}
+
+gdouble
+hdy_stackable_box_get_cancel_progress (HdyStackableBox *self)
+{
+  return 0;
+}
+
 gboolean
 hdy_stackable_box_captured_event (HdyStackableBox *self,
                                   GdkEvent        *event)
@@ -3050,41 +3157,26 @@ hdy_stackable_box_switch_child (HdyStackableBox *self,
                           duration, FALSE);
 }
 
-static double
-get_current_progress (HdyStackableBox *self)
+/* FIXME: This will go away in the next commits */
+static gdouble *
+get_snap_points_from_range (HdyStackableBox *self,
+                            gint            *n_snap_points)
 {
-  gboolean new_first = FALSE;
-  GList *children;
+  gint n;
+  gdouble *points, lower, upper;
 
-  if (!self->child_transition.is_gesture_active &&
-      gtk_progress_tracker_get_state (&self->child_transition.tracker) == GTK_PROGRESS_STATE_AFTER)
-    return 0;
+  hdy_stackable_box_get_range (self, &lower, &upper);
 
-  for (children = self->children; children; children = children->next) {
-    if (self->last_visible_child == children->data) {
-      new_first = TRUE;
+  n = (lower != upper) ? 2 : 1;
 
-      break;
-    }
-    if (self->visible_child == children->data)
-      break;
-  }
+  points = g_new0 (gdouble, n);
+  points[0] = lower;
+  points[n - 1] = upper;
 
-  return self->child_transition.progress * (new_first ? 1 : -1);
-}
+  if (n_snap_points)
+    *n_snap_points = n;
 
-static gboolean
-can_swipe_in_direction (HdyStackableBox        *self,
-                        HdyNavigationDirection  direction)
-{
-  switch (direction) {
-  case HDY_NAVIGATION_DIRECTION_BACK:
-    return self->child_transition.can_swipe_back;
-  case HDY_NAVIGATION_DIRECTION_FORWARD:
-    return self->child_transition.can_swipe_forward;
-  default:
-    g_assert_not_reached ();
-  }
+  return points;
 }
 
 void
@@ -3092,47 +3184,13 @@ hdy_stackable_box_begin_swipe (HdyStackableBox        *self,
                                HdyNavigationDirection  direction,
                                gboolean                direct)
 {
-  gint n;
-  gdouble *points, distance, progress;
+  gint n_snap_points;
+  gdouble *snap_points, distance, progress, cancel_progress;
 
-  if (self->orientation == GTK_ORIENTATION_HORIZONTAL)
-    distance = gtk_widget_get_allocated_width (GTK_WIDGET (self->container));
-  else
-    distance = gtk_widget_get_allocated_height (GTK_WIDGET (self->container));
+  self->child_transition.is_direct_swipe = direct;
+  self->child_transition.swipe_direction = direction;
 
   if (self->child_transition.tick_id > 0) {
-    gboolean is_rtl =
-      (gtk_widget_get_direction (GTK_WIDGET (self->container)) == GTK_TEXT_DIR_RTL);
-
-    n = 2;
-    points = g_new0 (gdouble, n);
-
-    switch (self->child_transition.active_direction) {
-    case GTK_PAN_DIRECTION_UP:
-      points[1] = 1;
-      break;
-    case GTK_PAN_DIRECTION_DOWN:
-      points[0] = -1;
-      break;
-    case GTK_PAN_DIRECTION_LEFT:
-      if (is_rtl)
-        points[0] = -1;
-      else
-        points[1] = 1;
-      break;
-    case GTK_PAN_DIRECTION_RIGHT:
-      if (is_rtl)
-        points[1] = 1;
-      else
-        points[0] = -1;
-      break;
-    default:
-      g_assert_not_reached ();
-    }
-
-    progress = get_current_progress (self);
-
-    gtk_widget_remove_tick_callback (GTK_WIDGET (self->container), self->child_transition.tick_id);
     self->child_transition.tick_id = 0;
     self->child_transition.is_gesture_active = TRUE;
     self->child_transition.is_cancelled = FALSE;
@@ -3151,25 +3209,15 @@ hdy_stackable_box_begin_swipe (HdyStackableBox        *self,
 
       g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CHILD_TRANSITION_RUNNING]);
     }
-
-    progress = 0;
-
-    n = child ? 2 : 1;
-    points = g_new0 (gdouble, n);
-    if (child)
-      switch (direction) {
-      case HDY_NAVIGATION_DIRECTION_BACK:
-        points[0] = -1;
-        break;
-      case HDY_NAVIGATION_DIRECTION_FORWARD:
-        points[1] = 1;
-        break;
-      default:
-        g_assert_not_reached ();
-      }
   }
 
-  hdy_swipe_tracker_confirm_swipe (self->tracker, distance, points, n, progress, 0);
+  distance = hdy_stackable_box_get_distance (self);
+  snap_points = get_snap_points_from_range (self, &n_snap_points);
+  progress = hdy_stackable_box_get_progress (self);
+  cancel_progress = hdy_stackable_box_get_cancel_progress (self);
+
+  hdy_swipe_tracker_confirm_swipe (self->tracker, distance, snap_points,
+                                   n_snap_points, progress, cancel_progress);
 }
 
 void
diff --git a/src/hdy-swipeable-private.h b/src/hdy-swipeable-private.h
index a33922fa..1fea7a9b 100644
--- a/src/hdy-swipeable-private.h
+++ b/src/hdy-swipeable-private.h
@@ -27,4 +27,13 @@ void hdy_swipeable_emit_switch_child (HdySwipeable *self,
                                       guint         index,
                                       gint64        duration);
 
+gdouble  hdy_swipeable_get_distance        (HdySwipeable *self);
+void     hdy_swipeable_get_range           (HdySwipeable *self,
+                                            gdouble      *lower,
+                                            gdouble      *upper);
+gdouble *hdy_swipeable_get_snap_points     (HdySwipeable *self,
+                                            gint         *n_snap_points);
+gdouble  hdy_swipeable_get_progress        (HdySwipeable *self);
+gdouble  hdy_swipeable_get_cancel_progress (HdySwipeable *self);
+
 G_END_DECLS
diff --git a/src/hdy-swipeable.c b/src/hdy-swipeable.c
index 9228ac7f..addd220a 100644
--- a/src/hdy-swipeable.c
+++ b/src/hdy-swipeable.c
@@ -269,3 +269,150 @@ hdy_swipeable_emit_switch_child (HdySwipeable *self,
 
   g_signal_emit (self, signals[SIGNAL_SWITCH_CHILD], 0, index, duration);
 }
+
+/**
+ * hdy_swipeable_get_distance:
+ * @self: a #HdySwipeable
+ *
+ * Gets the swipe distance of @self. This corresponds to how many pixels
+ * 1 unit represents.
+ *
+ * Returns: the swipe distance in pixels
+ *
+ * Since: 1.0
+ */
+gdouble
+hdy_swipeable_get_distance (HdySwipeable *self)
+{
+  HdySwipeableInterface *iface;
+
+  g_return_val_if_fail (HDY_IS_SWIPEABLE (self), 0);
+
+  iface = HDY_SWIPEABLE_GET_IFACE (self);
+  g_return_val_if_fail (iface->get_distance != NULL, 0);
+
+  return (* iface->get_distance) (self);
+}
+
+/**
+ * hdy_swipeable_get_range:
+ * @self: a #HdySwipeable
+ * @lower: (out) (allow-none): location to store the minimum possible value, or %NULL
+ * @upper: (out) (allow-none): location to store the maximum possible value, or %NULL
+ *
+ * Gets the range of possible progress values.
+ *
+ * Since: 1.0
+ */
+void
+hdy_swipeable_get_range (HdySwipeable *self,
+                         gdouble      *lower,
+                         gdouble      *upper)
+{
+  HdySwipeableInterface *iface;
+
+  g_return_if_fail (HDY_IS_SWIPEABLE (self));
+
+  iface = HDY_SWIPEABLE_GET_IFACE (self);
+  g_return_if_fail (iface->get_range != NULL);
+
+  (* iface->get_range) (self, lower, upper);
+}
+
+static gdouble *
+get_snap_points_from_range (HdySwipeable *self,
+                            gint         *n_snap_points)
+{
+  gint n;
+  gdouble *points, lower, upper;
+
+  hdy_swipeable_get_range (self, &lower, &upper);
+
+  n = (lower != upper) ? 2 : 1;
+
+  points = g_new0 (gdouble, n);
+  points[0] = lower;
+  points[n - 1] = upper;
+
+  if (n_snap_points)
+    *n_snap_points = n;
+
+  return points;
+}
+
+/**
+ * hdy_swipeable_get_snap_points:
+ * @self: a #HdySwipeable
+ * @n_snap_points: (out)
+ *
+ * Gets the snap points of @self. Each snap point represents a progress value
+ * that is considered acceptable to end the swipe on.
+ *
+ * If not implemented, the default implementation returns one snap point for
+ * each end of the range, or just one snap point if they are equal.
+ *
+ * Returns: (array length=n_snap_points) (transfer full): the snap points of @self
+ *
+ * Since: 1.0
+ */
+gdouble *
+hdy_swipeable_get_snap_points (HdySwipeable *self,
+                               gint         *n_snap_points)
+{
+  HdySwipeableInterface *iface;
+
+  g_return_val_if_fail (HDY_IS_SWIPEABLE (self), NULL);
+
+  iface = HDY_SWIPEABLE_GET_IFACE (self);
+
+  if (iface->get_snap_points)
+    return (* iface->get_snap_points) (self, n_snap_points);
+
+  return get_snap_points_from_range (self, n_snap_points);
+}
+
+/**
+ * hdy_swipeable_get_progress:
+ * @self: a #HdySwipeable
+ *
+ * Gets the current progress of @self
+ *
+ * Returns: the current progress, unitless
+ *
+ * Since: 1.0
+ */
+gdouble
+hdy_swipeable_get_progress (HdySwipeable *self)
+{
+  HdySwipeableInterface *iface;
+
+  g_return_val_if_fail (HDY_IS_SWIPEABLE (self), 0);
+
+  iface = HDY_SWIPEABLE_GET_IFACE (self);
+  g_return_val_if_fail (iface->get_progress != NULL, 0);
+
+  return (* iface->get_progress) (self);
+}
+
+/**
+ * hdy_swipeable_get_cancel_progress:
+ * @self: a #HdySwipeable
+ *
+ * Gets the progress @self will snap back to after the gesture is canceled.
+ *
+ * Returns: the cancel progress, unitless
+ *
+ * Since: 1.0
+ */
+gdouble
+hdy_swipeable_get_cancel_progress (HdySwipeable *self)
+{
+  HdySwipeableInterface *iface;
+
+  g_return_val_if_fail (HDY_IS_SWIPEABLE (self), 0);
+
+  iface = HDY_SWIPEABLE_GET_IFACE (self);
+  g_return_val_if_fail (iface->get_cancel_progress != NULL, 0);
+
+  return (* iface->get_cancel_progress) (self);
+}
diff --git a/src/hdy-swipeable.h b/src/hdy-swipeable.h
index 9f291024..fe0865ed 100644
--- a/src/hdy-swipeable.h
+++ b/src/hdy-swipeable.h
@@ -22,6 +22,11 @@ G_DECLARE_INTERFACE (HdySwipeable, hdy_swipeable, HDY, SWIPEABLE, GtkWidget)
  * @begin_swipe: Starts a swipe gesture.
  * @update_swipe: Updates swipe progress value.
  * @end_swipe: Ends a swipe gesture.
+ * @get_distance: Gets the swipe distance.
+ * @get_range: Gets the range of progress values.
+ * @get_snap_points: Gets the snap points
+ * @get_progress: Gets the current progress.
+ * @get_cancel_progress: Gets the cancel progress.
  *
  * An interface for swipeable widgets.
  *
@@ -42,6 +47,15 @@ struct _HdySwipeableInterface
   void (*end_swipe)    (HdySwipeable *self,
                         gint64        duration,
                         gdouble       to);
+
+  gdouble   (*get_distance)        (HdySwipeable *self);
+  void      (*get_range)           (HdySwipeable *self,
+                                    gdouble      *min_progress,
+                                    gdouble      *max_progress);
+  gdouble * (*get_snap_points)     (HdySwipeable *self,
+                                    gint         *n_snap_points);
+  gdouble   (*get_progress)        (HdySwipeable *self);
+  gdouble   (*get_cancel_progress) (HdySwipeable *self);
 };
 
 G_END_DECLS


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