[libhandy/wip/exalm/paginator-animate: 29/41] carousel-box: Add hdy_carousel_box_get_page_at_position()



commit 55ec7ba2e95a690777365ec52c20e658a0449b0a
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sun Dec 29 17:32:07 2019 +0500

    carousel-box: Add hdy_carousel_box_get_page_at_position()
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 src/hdy-carousel-box-private.h |  2 ++
 src/hdy-carousel-box.c         | 31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
---
diff --git a/src/hdy-carousel-box-private.h b/src/hdy-carousel-box-private.h
index 7859f471..0cb28122 100644
--- a/src/hdy-carousel-box-private.h
+++ b/src/hdy-carousel-box-private.h
@@ -57,5 +57,7 @@ void            hdy_carousel_box_get_range              (HdyCarouselBox *self,
                                                          gdouble        *lower,
                                                          gdouble        *upper);
 gdouble         hdy_carousel_box_get_closest_snap_point (HdyCarouselBox *self);
+GtkWidget      *hdy_carousel_box_get_page_at_position   (HdyCarouselBox *self,
+                                                         gdouble         position);
 
 G_END_DECLS
diff --git a/src/hdy-carousel-box.c b/src/hdy-carousel-box.c
index d3d291c1..b7a7dab2 100644
--- a/src/hdy-carousel-box.c
+++ b/src/hdy-carousel-box.c
@@ -1275,3 +1275,34 @@ hdy_carousel_box_get_closest_snap_point (HdyCarouselBox *self)
   return CLAMP (round (self->position), 0,
                 hdy_carousel_box_get_n_pages (self) - 1);
 }
+
+/**
+ * hdy_carousel_box_get_page_at_position:
+ * @self: a #HdyCarouselBox
+ * @position: a scroll position
+ *
+ * Gets the page closest to @position. For example, if @position matches
+ * the current position, the returned widget will match the currently
+ * displayed page.
+ *
+ * Returns: the closest page.
+ *
+ * Since: 1.0
+ */
+GtkWidget *
+hdy_carousel_box_get_page_at_position (HdyCarouselBox *self,
+                                       gdouble         position)
+{
+  gdouble lower, upper;
+  gint n;
+
+  g_return_val_if_fail (HDY_IS_CAROUSEL_BOX (self), NULL);
+
+  hdy_carousel_box_get_range (self, &lower, &upper);
+
+  position = CLAMP (position, lower, upper);
+
+  n = round (position);
+
+  return hdy_carousel_box_get_nth_child (self, n);
+}


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