[libadwaita/wip/exalm/properties: 3/5] animation: Add set_target()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/properties: 3/5] animation: Add set_target()
- Date: Mon, 20 Jun 2022 21:54:51 +0000 (UTC)
commit 85af8c08f8762aecbd368ec77d19756599968a94
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Jun 21 00:03:19 2022 +0400
animation: Add set_target()
That property was readwrite and we didn't have a setter.
src/adw-animation.c | 35 +++++++++++++++++++++++++++++++----
src/adw-animation.h | 5 ++++-
tests/test-animation.c | 6 ++++++
3 files changed, 41 insertions(+), 5 deletions(-)
---
diff --git a/src/adw-animation.c b/src/adw-animation.c
index eadaf36c..4da17247 100644
--- a/src/adw-animation.c
+++ b/src/adw-animation.c
@@ -312,7 +312,6 @@ adw_animation_set_property (GObject *object,
GParamSpec *pspec)
{
AdwAnimation *self = ADW_ANIMATION (object);
- AdwAnimationPrivate *priv = adw_animation_get_instance_private (self);
switch (prop_id) {
case PROP_WIDGET:
@@ -320,7 +319,7 @@ adw_animation_set_property (GObject *object,
break;
case PROP_TARGET:
- g_set_object (&priv->target, g_value_get_object (value));
+ adw_animation_set_target (ADW_ANIMATION (self), g_value_get_object (value));
break;
default:
@@ -379,7 +378,7 @@ adw_animation_class_init (AdwAnimationClass *klass)
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
/**
- * AdwAnimation:target: (attributes org.gtk.Property.get=adw_animation_get_target)
+ * AdwAnimation:target: (attributes org.gtk.Property.get=adw_animation_get_target
org.gtk.Property.set=adw_animation_set_target)
*
* The target to animate.
*
@@ -390,7 +389,7 @@ adw_animation_class_init (AdwAnimationClass *klass)
"Target",
"The target to animate",
ADW_TYPE_ANIMATION_TARGET,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS |
G_PARAM_EXPLICIT_NOTIFY);
/**
* AdwAnimation:state: (attributes org.gtk.Property.get=adw_animation_get_state)
@@ -482,6 +481,34 @@ adw_animation_get_target (AdwAnimation *self)
return priv->target;
}
+/**
+ * adw_animation_set_target: (attributes org.gtk.Method.set_property=target)
+ * @self: an animation
+ * @target: an animation target
+ *
+ * Sets the target @self animates to @target.
+ *
+ * Since: 1.0
+ */
+void
+adw_animation_set_target (AdwAnimation *self,
+ AdwAnimationTarget *target)
+{
+ AdwAnimationPrivate *priv;
+
+ g_return_if_fail (ADW_IS_ANIMATION (self));
+ g_return_if_fail (ADW_IS_ANIMATION_TARGET (target));
+
+ priv = adw_animation_get_instance_private (self);
+
+ if (target == priv->target)
+ return;
+
+ g_set_object (&priv->target, target);
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_TARGET]);
+}
+
/**
* adw_animation_get_value: (attributes org.gtk.Method.get_property=value)
* @self: an animation
diff --git a/src/adw-animation.h b/src/adw-animation.h
index c28e83c6..29673c8a 100644
--- a/src/adw-animation.h
+++ b/src/adw-animation.h
@@ -46,7 +46,10 @@ ADW_AVAILABLE_IN_ALL
GtkWidget *adw_animation_get_widget (AdwAnimation *self);
ADW_AVAILABLE_IN_ALL
-AdwAnimationTarget *adw_animation_get_target (AdwAnimation *self);
+AdwAnimationTarget *adw_animation_get_target (AdwAnimation *self);
+ADW_AVAILABLE_IN_ALL
+void adw_animation_set_target (AdwAnimation *self,
+ AdwAnimationTarget *target);
ADW_AVAILABLE_IN_ALL
double adw_animation_get_value (AdwAnimation *self);
diff --git a/tests/test-animation.c b/tests/test-animation.c
index 252f2930..0de9410e 100644
--- a/tests/test-animation.c
+++ b/tests/test-animation.c
@@ -30,6 +30,8 @@ test_adw_animation_general (void)
GtkWidget *widget = g_object_ref_sink (gtk_button_new ());
AdwAnimationTarget *target =
adw_callback_animation_target_new (value_cb, NULL, NULL);
+ AdwAnimationTarget *target2 =
+ adw_callback_animation_target_new (value_cb, NULL, NULL);
AdwAnimation *animation =
adw_timed_animation_new (widget, 10, 20, 100, g_object_ref (target));
@@ -69,8 +71,12 @@ test_adw_animation_general (void)
g_assert_cmpfloat (last_value, ==, 20);
g_assert_cmpint (done_count, ==, 2);
+ adw_animation_set_target (animation, target2);
+ g_assert_true (adw_animation_get_target (animation) == target2);
+
g_assert_finalize_object (animation);
g_assert_finalize_object (target);
+ g_assert_finalize_object (target2);
g_assert_finalize_object (widget);
g_assert_cmpfloat (last_value, ==, 20);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]