[libhandy/wip/exalm/paginator-animate: 66/78] carousel-box: Add hdy_carousel_box_get_page_at_position()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/wip/exalm/paginator-animate: 66/78] carousel-box: Add hdy_carousel_box_get_page_at_position()
- Date: Fri, 22 May 2020 13:34:18 +0000 (UTC)
commit 0ee893e3fe47c4963a650794998797dc097f6a98
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]