[libadwaita] carousel: Add the allow-scroll-wheel prop
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita] carousel: Add the allow-scroll-wheel prop
- Date: Thu, 29 Apr 2021 09:33:36 +0000 (UTC)
commit f9312f9025bf362a307f2c40249828f39dbf1280
Author: Adrien Plazas <kekun plazas laposte net>
Date: Thu Apr 29 07:26:39 2021 +0200
carousel: Add the allow-scroll-wheel prop
src/adw-carousel.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/adw-carousel.h | 6 +++++
2 files changed, 81 insertions(+)
---
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 04bc851..12a06fb 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -42,6 +42,8 @@ struct _AdwCarousel
AdwSwipeTracker *tracker;
+ gboolean allow_scroll_wheel;
+
GtkOrientation orientation;
guint animation_duration;
@@ -67,6 +69,7 @@ enum {
PROP_SPACING,
PROP_ANIMATION_DURATION,
PROP_ALLOW_MOUSE_DRAG,
+ PROP_ALLOW_SCROLL_WHEEL,
PROP_ALLOW_LONG_SWIPES,
PROP_REVEAL_DURATION,
@@ -275,6 +278,9 @@ scroll_cb (AdwCarousel *self,
GtkOrientation orientation;
guint duration;
+ if (!self->allow_scroll_wheel)
+ return GDK_EVENT_PROPAGATE;
+
if (!self->can_scroll)
return GDK_EVENT_PROPAGATE;
@@ -389,6 +395,10 @@ adw_carousel_get_property (GObject *object,
g_value_set_boolean (value, adw_carousel_get_allow_mouse_drag (self));
break;
+ case PROP_ALLOW_SCROLL_WHEEL:
+ g_value_set_boolean (value, adw_carousel_get_allow_scroll_wheel (self));
+ break;
+
case PROP_ALLOW_LONG_SWIPES:
g_value_set_boolean (value, adw_carousel_get_allow_long_swipes (self));
break;
@@ -439,6 +449,10 @@ adw_carousel_set_property (GObject *object,
adw_carousel_set_allow_mouse_drag (self, g_value_get_boolean (value));
break;
+ case PROP_ALLOW_SCROLL_WHEEL:
+ adw_carousel_set_allow_scroll_wheel (self, g_value_get_boolean (value));
+ break;
+
case PROP_ALLOW_LONG_SWIPES:
adw_carousel_set_allow_long_swipes (self, g_value_get_boolean (value));
break;
@@ -575,6 +589,21 @@ adw_carousel_class_init (AdwCarouselClass *klass)
TRUE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * AdwCarousel:allow-scroll-wheel:
+ *
+ * Whether the widget will respond to scroll wheel events. If the value is
+ * %FALSE, wheel events will be ignored.
+ *
+ * Since: 1.0
+ */
+ props[PROP_ALLOW_SCROLL_WHEEL] =
+ g_param_spec_boolean ("allow-scroll-wheel",
+ "Allow scroll wheel",
+ "Whether the widget will respond to scroll wheel events",
+ TRUE,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
/**
* AdwCarousel:allow-long-swipes:
*
@@ -651,6 +680,8 @@ adw_carousel_class_init (AdwCarouselClass *klass)
static void
adw_carousel_init (AdwCarousel *self)
{
+ self->allow_scroll_wheel = TRUE;
+
g_type_ensure (ADW_TYPE_CAROUSEL_BOX);
gtk_widget_init_template (GTK_WIDGET (self));
@@ -1076,6 +1107,50 @@ adw_carousel_set_allow_mouse_drag (AdwCarousel *self,
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_MOUSE_DRAG]);
}
+/**
+ * adw_carousel_get_allow_scroll_wheel:
+ * @self: a #AdwCarousel
+ *
+ * Gets whether @self will respond to scroll wheel events.
+ *
+ * Returns: %TRUE if @self will respond to scroll wheel events
+ *
+ * Since: 1.0
+ */
+gboolean
+adw_carousel_get_allow_scroll_wheel (AdwCarousel *self)
+{
+ g_return_val_if_fail (ADW_IS_CAROUSEL (self), FALSE);
+
+ return self->allow_scroll_wheel;
+}
+
+/**
+ * adw_carousel_set_allow_scroll_wheel:
+ * @self: a #AdwCarousel
+ * @allow_scroll_wheel: whether @self will respond to scroll wheel events.
+ *
+ * Sets whether @self will respond to scroll wheel events. If the value is
+ * %FALSE, wheel events will be ignored.
+ *
+ * Since: 1.0
+ */
+void
+adw_carousel_set_allow_scroll_wheel (AdwCarousel *self,
+ gboolean allow_scroll_wheel)
+{
+ g_return_if_fail (ADW_IS_CAROUSEL (self));
+
+ allow_scroll_wheel = !!allow_scroll_wheel;
+
+ if (self->allow_scroll_wheel == allow_scroll_wheel)
+ return;
+
+ self->allow_scroll_wheel = allow_scroll_wheel;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ALLOW_SCROLL_WHEEL]);
+}
+
/**
* adw_carousel_get_allow_long_swipes:
* @self: a #AdwCarousel
diff --git a/src/adw-carousel.h b/src/adw-carousel.h
index 4e92956..311d6cf 100644
--- a/src/adw-carousel.h
+++ b/src/adw-carousel.h
@@ -84,6 +84,12 @@ ADW_AVAILABLE_IN_ALL
void adw_carousel_set_allow_mouse_drag (AdwCarousel *self,
gboolean allow_mouse_drag);
+ADW_AVAILABLE_IN_ALL
+gboolean adw_carousel_get_allow_scroll_wheel (AdwCarousel *self);
+ADW_AVAILABLE_IN_ALL
+void adw_carousel_set_allow_scroll_wheel (AdwCarousel *self,
+ gboolean allow_scroll_wheel);
+
ADW_AVAILABLE_IN_ALL
gboolean adw_carousel_get_allow_long_swipes (AdwCarousel *self);
ADW_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]