[libadwaita/bilelmoussaoui/animation-target-fn: 46/47] animation-target: Make the user_data last param




commit 2749893e56d7a3b15d7470f458f9e4f1f8c1bfe9
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date:   Sat Nov 27 20:29:45 2021 +0100

    animation-target: Make the user_data last param
    
    Otherwise bindings confuses the value for the user_data. In general, it's
    supposed to be the last param.

 demo/adw-demo-window.c             |  9 ++++++++-
 src/adw-animation-target.c         |  2 +-
 src/adw-animation-target.h         |  6 +++---
 src/adw-animation.c                |  4 ++--
 src/adw-carousel-indicator-dots.c  | 10 ++++++++--
 src/adw-carousel-indicator-lines.c | 10 ++++++++--
 src/adw-carousel.c                 |  8 ++++----
 src/adw-flap.c                     | 10 +++++-----
 src/adw-leaflet.c                  | 10 +++++-----
 src/adw-squeezer.c                 |  4 ++--
 src/adw-tab-box.c                  | 31 +++++++++++++++++++------------
 src/adw-tab.c                      |  4 ++--
 src/adw-toast-overlay.c            | 13 ++++++++++---
 tests/test-animation.c             |  4 ++--
 tests/test-timed-animation.c       |  4 ++--
 15 files changed, 81 insertions(+), 48 deletions(-)
---
diff --git a/demo/adw-demo-window.c b/demo/adw-demo-window.c
index 81324159..c4cb8cb8 100644
--- a/demo/adw-demo-window.c
+++ b/demo/adw-demo-window.c
@@ -612,6 +612,13 @@ timed_animation_can_skip (gpointer          user_data,
   return state != ADW_ANIMATION_FINISHED;
 }
 
+static void
+timed_animation_cb (double     value,
+                    GtkWidget *self)
+{
+  gtk_widget_queue_allocate (self);
+}
+
 static void
 style_classes_demo_clicked_cb (GtkButton     *btn,
                                AdwDemoWindow *self)
@@ -812,7 +819,7 @@ animation_page_init (AdwDemoWindow *self)
   GtkLayoutManager *manager;
   AdwAnimationTarget *target =
     adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                       gtk_widget_queue_allocate,
+                                       timed_animation_cb,
                                        self->timed_animation_sample, NULL);
 
   self->timed_animation =
diff --git a/src/adw-animation-target.c b/src/adw-animation-target.c
index 379487d7..337359c5 100644
--- a/src/adw-animation-target.c
+++ b/src/adw-animation-target.c
@@ -85,7 +85,7 @@ adw_callback_animation_target_set_value (AdwAnimationTarget *target,
 {
   AdwCallbackAnimationTarget *self = ADW_CALLBACK_ANIMATION_TARGET (target);
 
-  self->callback (self->user_data, value);
+  self->callback (value, self->user_data);
 }
 
 static void
diff --git a/src/adw-animation-target.h b/src/adw-animation-target.h
index 42483d04..6f9c4383 100644
--- a/src/adw-animation-target.h
+++ b/src/adw-animation-target.h
@@ -24,15 +24,15 @@ GDK_DECLARE_INTERNAL_TYPE (AdwAnimationTarget, adw_animation_target, ADW, ANIMAT
 
 /**
  * AdwAnimationTargetFunc:
- * @user_data: (nullable): The user data provided when creating the target
  * @value: The animation value
+ * @user_data: (nullable): The user data provided when creating the target
  *
  * Prototype for animation targets based on user callbacks.
  *
  * Since: 1.0
  */
-typedef void (*AdwAnimationTargetFunc) (gpointer user_data,
-                                        double   value);
+typedef void (*AdwAnimationTargetFunc) (double   value,
+                                        gpointer user_data);
 
 #define ADW_TYPE_CALLBACK_ANIMATION_TARGET (adw_callback_animation_target_get_type())
 
diff --git a/src/adw-animation.c b/src/adw-animation.c
index fc5d91c2..bb46fc37 100644
--- a/src/adw-animation.c
+++ b/src/adw-animation.c
@@ -38,8 +38,8 @@
  *
  * ```c
  * static void
- * animation_cb (MyObject *self,
- *               double    value)
+ * animation_cb (double    value,
+ *               MyObject *self)
  * {
  *   // Do something with @value
  * }
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index d3bf2a5f..5209124a 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -166,6 +166,13 @@ snapshot_dots (GtkWidget      *widget,
   }
 }
 
+static void
+animation_cb (double     value,
+              GtkWidget *self)
+{
+  gtk_widget_queue_resize (self);
+}
+
 static void
 adw_carousel_indicator_dots_measure (GtkWidget      *widget,
                                      GtkOrientation  orientation,
@@ -338,8 +345,7 @@ static void
 adw_carousel_indicator_dots_init (AdwCarouselIndicatorDots *self)
 {
   AdwAnimationTarget *target
-    = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                         gtk_widget_queue_resize,
+    = adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb,
                                          self, NULL);
 
   self->animation =
diff --git a/src/adw-carousel-indicator-lines.c b/src/adw-carousel-indicator-lines.c
index 97c8df32..72c97ded 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -151,6 +151,13 @@ snapshot_lines (GtkWidget      *widget,
                                &GRAPHENE_RECT_INIT (x, y + pos, LINE_WIDTH, LINE_LENGTH));
 }
 
+static void
+animation_cb (double     value,
+              GtkWidget *self)
+{
+  gtk_widget_queue_resize (self);
+}
+
 static void
 adw_carousel_indicator_lines_measure (GtkWidget      *widget,
                                       GtkOrientation  orientation,
@@ -323,8 +330,7 @@ static void
 adw_carousel_indicator_lines_init (AdwCarouselIndicatorLines *self)
 {
   AdwAnimationTarget *target
-    = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                         gtk_widget_queue_resize,
+    = adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb,
                                          self, NULL);
 
   self->animation =
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 427e5b3d..045e096d 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -279,8 +279,8 @@ set_position (AdwCarousel *self,
 }
 
 static void
-resize_animation_value_cb (ChildInfo *child,
-                           double     value)
+resize_animation_value_cb (double     value,
+                           ChildInfo *child)
 {
   AdwCarousel *self = ADW_CAROUSEL (adw_animation_get_widget (child->resize_animation));
   double delta = value - child->size;
@@ -348,8 +348,8 @@ shift_position (AdwCarousel *self,
 }
 
 static void
-scroll_animation_value_cb (AdwCarousel *self,
-                           double       value)
+scroll_animation_value_cb (double       value,
+                           AdwCarousel *self)
 {
   set_position (self, value);
 
diff --git a/src/adw-flap.c b/src/adw-flap.c
index 5644e90b..6d892851 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -263,8 +263,8 @@ update_shortcuts (AdwFlap *self)
 }
 
 static void
-set_reveal_progress (AdwFlap *self,
-                     double   progress)
+set_reveal_progress (double   progress,
+                     AdwFlap *self)
 {
   self->reveal_progress = progress;
 
@@ -275,8 +275,8 @@ set_reveal_progress (AdwFlap *self,
 }
 
 static void
-fold_animation_value_cb (AdwFlap *self,
-                         double   value)
+fold_animation_value_cb (double   value,
+                         AdwFlap *self)
 {
   self->fold_progress = value;
 
@@ -414,7 +414,7 @@ update_swipe_cb (AdwSwipeTracker *tracker,
                  double           progress,
                  AdwFlap         *self)
 {
-  set_reveal_progress (self, progress);
+  set_reveal_progress (progress, self);
 }
 
 static void
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index 59397a05..5c076b1d 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -616,8 +616,8 @@ set_child_transition_running (AdwLeaflet *self,
 }
 
 static void
-child_transition_cb (AdwLeaflet *self,
-                     double      value)
+child_transition_cb (double      value,
+                     AdwLeaflet *self)
 {
   self->child_transition.progress = value;
 
@@ -820,8 +820,8 @@ set_visible_child (AdwLeaflet               *self,
 }
 
 static void
-mode_transition_cb (AdwLeaflet *self,
-                    double      value)
+mode_transition_cb (double      value,
+                    AdwLeaflet *self)
 {
   self->mode_transition.current_pos = value;
 
@@ -1461,7 +1461,7 @@ update_swipe_cb (AdwSwipeTracker *tracker,
                  double           progress,
                  AdwLeaflet      *self)
 {
-  child_transition_cb (self, ABS (progress));
+  child_transition_cb (ABS (progress), self);
 }
 
 static void
diff --git a/src/adw-squeezer.c b/src/adw-squeezer.c
index 8c989cb2..7bbd4e6e 100644
--- a/src/adw-squeezer.c
+++ b/src/adw-squeezer.c
@@ -378,8 +378,8 @@ find_page_for_widget (AdwSqueezer *self,
 }
 
 static void
-transition_cb (AdwSqueezer *self,
-               double       value)
+transition_cb (double       value,
+               AdwSqueezer *self)
 {
   if (!self->homogeneous)
     gtk_widget_queue_resize (GTK_WIDGET (self));
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index 1effdea5..6b895a8a 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -880,6 +880,13 @@ scroll_cb (AdwTabBox          *self,
   return GDK_EVENT_STOP;
 }
 
+static void
+scroll_animation_cb (double     value,
+                     GtkWidget *self)
+{
+  gtk_widget_queue_resize (self);
+}
+
 /* Reordering */
 
 static void
@@ -963,8 +970,8 @@ get_reorder_position (AdwTabBox *self)
 }
 
 static void
-reorder_animation_value_cb (TabInfo *dest_tab,
-                            double   value)
+reorder_animation_value_cb (double   value,
+                            TabInfo *dest_tab)
 {
   GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (dest_tab->tab));
   AdwTabBox *self = ADW_TAB_BOX (parent);
@@ -1014,8 +1021,8 @@ animate_reordering (AdwTabBox *self,
 }
 
 static void
-reorder_offset_animation_value_cb (TabInfo *info,
-                                   double   value)
+reorder_offset_animation_value_cb (double   value,
+                                   TabInfo *info)
 {
   GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (info->tab));
 
@@ -1564,8 +1571,8 @@ extra_drag_drop_cb (AdwTab    *tab,
 }
 
 static void
-appear_animation_value_cb (TabInfo *info,
-                           double   value)
+appear_animation_value_cb (double   value,
+                           TabInfo *info)
 {
   info->appear_progress = value;
 
@@ -1875,12 +1882,12 @@ calculate_placeholder_index (AdwTabBox *self,
 }
 
 static void
-insert_animation_value_cb (TabInfo *info,
-                           double   value)
+insert_animation_value_cb (double   value,
+                           TabInfo *info)
 {
   AdwTabBox *self = ADW_TAB_BOX (gtk_widget_get_parent (GTK_WIDGET (info->tab)));
 
-  appear_animation_value_cb (info, value);
+  appear_animation_value_cb (value, info);
 
   update_drag_reodering (self);
 }
@@ -2203,8 +2210,8 @@ tab_drag_cancel_cb (AdwTabBox           *self,
 }
 
 static void
-icon_resize_animation_value_cb (DragIcon *icon,
-                                double    value)
+icon_resize_animation_value_cb (double    value,
+                                DragIcon *icon)
 {
   double relative_pos;
 
@@ -3448,7 +3455,7 @@ adw_tab_box_init (AdwTabBox *self)
    * well after one last update, so that we don't miss the last frame.
    */
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              gtk_widget_queue_resize,
+                                              scroll_animation_cb,
                                               self, NULL);
   self->scroll_animation =
     adw_timed_animation_new (GTK_WIDGET (self), 0, 1,
diff --git a/src/adw-tab.c b/src/adw-tab.c
index 55dad957..9c1c55df 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -87,8 +87,8 @@ set_style_class (GtkWidget  *widget,
 }
 
 static void
-close_btn_animation_value_cb (AdwTab *self,
-                              double  value)
+close_btn_animation_value_cb (double  value,
+                              AdwTab *self)
 {
   gtk_widget_set_opacity (self->close_btn, value);
   gtk_widget_set_can_target (self->close_btn, value > 0);
diff --git a/src/adw-toast-overlay.c b/src/adw-toast-overlay.c
index b76c0b72..8a3a8e3c 100644
--- a/src/adw-toast-overlay.c
+++ b/src/adw-toast-overlay.c
@@ -121,8 +121,8 @@ dismiss_and_free_toast_info (ToastInfo *info)
 }
 
 static void
-hide_value_cb (ToastInfo *info,
-               double     value)
+hide_value_cb (double     value,
+               ToastInfo *info)
 {
   value = adw_easing_ease (ADW_EASE_OUT_CUBIC, value);
   gtk_widget_set_opacity (info->widget, value);
@@ -215,6 +215,13 @@ dismissed_cb (ToastInfo *info)
   }
 }
 
+static void
+show_toast_animation_cb (double     value,
+                         GtkWidget *self)
+{
+  gtk_widget_queue_allocate (self);
+}
+
 static void
 show_toast (AdwToastOverlay *self,
             ToastInfo       *info)
@@ -229,7 +236,7 @@ show_toast (AdwToastOverlay *self,
   gtk_widget_insert_before (info->widget, GTK_WIDGET (self), NULL);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              gtk_widget_queue_allocate,
+                                              show_toast_animation_cb,
                                               self, NULL);
   info->show_animation =
     adw_timed_animation_new (GTK_WIDGET (self), 0, 1,
diff --git a/tests/test-animation.c b/tests/test-animation.c
index 2701f028..252f2930 100644
--- a/tests/test-animation.c
+++ b/tests/test-animation.c
@@ -12,8 +12,8 @@ static double last_value;
 static int done_count;
 
 static void
-value_cb (gpointer user_data,
-          double   value)
+value_cb (double   value,
+          gpointer user_data)
 {
   last_value = value;
 }
diff --git a/tests/test-timed-animation.c b/tests/test-timed-animation.c
index 679b1f3a..78e7db69 100644
--- a/tests/test-timed-animation.c
+++ b/tests/test-timed-animation.c
@@ -11,8 +11,8 @@
 int notified;
 
 static void
-value_cb (gpointer user_data,
-          double   value)
+value_cb (double   value,
+          gpointer user_data)
 {
 }
 


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