[libhandy] swipeable: Add get_swipe_area()



commit 56ebb689bf0fb8026f79f009d5594cac19523754
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Jun 26 18:57:22 2020 +0500

    swipeable: Add get_swipe_area()
    
    This will help with https://gitlab.gnome.org/GNOME/libhandy/-/issues/167
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-swipeable-private.h |  2 ++
 src/hdy-swipeable.c         | 39 +++++++++++++++++++++++++++++++++++++++
 src/hdy-swipeable.h         |  3 +++
 3 files changed, 44 insertions(+)
---
diff --git a/src/hdy-swipeable-private.h b/src/hdy-swipeable-private.h
index e3c2c657..77357573 100644
--- a/src/hdy-swipeable-private.h
+++ b/src/hdy-swipeable-private.h
@@ -27,5 +27,7 @@ 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);
+void     hdy_swipeable_get_swipe_area      (HdySwipeable *self,
+                                            GdkRectangle *rect);
 
 G_END_DECLS
diff --git a/src/hdy-swipeable.c b/src/hdy-swipeable.c
index 9909230d..c854365d 100644
--- a/src/hdy-swipeable.c
+++ b/src/hdy-swipeable.c
@@ -254,3 +254,42 @@ hdy_swipeable_get_cancel_progress (HdySwipeable *self)
 
   return (* iface->get_cancel_progress) (self);
 }
+
+/**
+ * hdy_swipeable_get_swipe_area:
+ * @self: a #HdySwipeable
+ * @rect: (out): a pointer to a #GdkRectangle to store the swipe area
+ *
+ * Gets the area @self can start a swipe from. This can be used to restrict
+ * swipes to only be possible from a certain area, for example, to only allow
+ * edge swipes, or to have a draggable element and ignore swipes elsewhere.
+ *
+ * Swipe area is only considered for direct swipes (as in, not initiated by
+ * #HdySwipeGroup).
+ *
+ * If not implemented, the default implementation returns the allocation of
+ * @self, allowing swipes from anywhere.
+ *
+ * Since: 1.0
+ */
+void
+hdy_swipeable_get_swipe_area (HdySwipeable *self,
+                              GdkRectangle *rect)
+{
+  HdySwipeableInterface *iface;
+
+  g_return_if_fail (HDY_IS_SWIPEABLE (self));
+  g_return_if_fail (rect != NULL);
+
+  iface = HDY_SWIPEABLE_GET_IFACE (self);
+
+  if (iface->get_swipe_area) {
+    (* iface->get_swipe_area) (self, rect);
+    return;
+  }
+
+  rect->x = 0;
+  rect->y = 0;
+  rect->width = gtk_widget_get_allocated_width (GTK_WIDGET (self));
+  rect->height = gtk_widget_get_allocated_height (GTK_WIDGET (self));
+}
diff --git a/src/hdy-swipeable.h b/src/hdy-swipeable.h
index cb7ee5b2..5c4f4ef5 100644
--- a/src/hdy-swipeable.h
+++ b/src/hdy-swipeable.h
@@ -28,6 +28,7 @@ G_DECLARE_INTERFACE (HdySwipeable, hdy_swipeable, HDY, SWIPEABLE, GtkWidget)
  * @get_snap_points: Gets the snap points
  * @get_progress: Gets the current progress.
  * @get_cancel_progress: Gets the cancel progress.
+ * @get_swipe_area: Gets the swipeable rectangle.
  *
  * An interface for swipeable widgets.
  *
@@ -49,6 +50,8 @@ struct _HdySwipeableInterface
                                     gint         *n_snap_points);
   gdouble   (*get_progress)        (HdySwipeable *self);
   gdouble   (*get_cancel_progress) (HdySwipeable *self);
+  void      (*get_swipe_area)      (HdySwipeable *self,
+                                    GdkRectangle *rect);
 };
 
 G_END_DECLS


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