[libadwaita/wip/exalm/animation-cleanup: 6/10] animation-target: Swap value and data in the callback




commit bb917e36c2a4347fa1d31b569af700d2994be5d7
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Nov 16 18:27:36 2021 +0500

    animation-target: Swap value and data in the callback
    
    Make it easier to use, same as swapped signal handlers.

 src/adw-animation-target-private.h |  4 ++--
 src/adw-animation-target.c         |  2 +-
 src/adw-carousel-indicator-dots.c  |  9 +--------
 src/adw-carousel-indicator-lines.c |  9 +--------
 src/adw-carousel.c                 |  8 ++++----
 src/adw-flap.c                     | 13 +++----------
 src/adw-tab-box.c                  | 31 ++++++++++++-------------------
 src/adw-tab.c                      |  4 ++--
 src/adw-toast-overlay.c            | 15 ++++-----------
 9 files changed, 30 insertions(+), 65 deletions(-)
---
diff --git a/src/adw-animation-target-private.h b/src/adw-animation-target-private.h
index 2f506a2b..bfa7006f 100644
--- a/src/adw-animation-target-private.h
+++ b/src/adw-animation-target-private.h
@@ -25,8 +25,8 @@ void adw_animation_target_set_value (AdwAnimationTarget *self,
 
 
 
-typedef void (*AdwAnimationTargetFunc) (double   value,
-                                        gpointer user_data);
+typedef void (*AdwAnimationTargetFunc) (gpointer user_data,
+                                        double   value);
 
 #define ADW_TYPE_CALLBACK_ANIMATION_TARGET (adw_callback_animation_target_get_type())
 
diff --git a/src/adw-animation-target.c b/src/adw-animation-target.c
index 8961396e..87488962 100644
--- a/src/adw-animation-target.c
+++ b/src/adw-animation-target.c
@@ -64,7 +64,7 @@ adw_callback_animation_target_set_value (AdwAnimationTarget *target,
 {
   AdwCallbackAnimationTarget *self = ADW_CALLBACK_ANIMATION_TARGET (target);
 
-  self->callback (value, self->user_data);
+  self->callback (self->user_data, value);
 }
 
 static void
diff --git a/src/adw-carousel-indicator-dots.c b/src/adw-carousel-indicator-dots.c
index 4b97433b..e1be8a57 100644
--- a/src/adw-carousel-indicator-dots.c
+++ b/src/adw-carousel-indicator-dots.c
@@ -66,13 +66,6 @@ enum {
 
 static GParamSpec *props[LAST_PROP];
 
-static void
-value_cb (double     value,
-          GtkWidget *widget)
-{
-  gtk_widget_queue_draw (widget);
-}
-
 static void
 done_cb (AdwCarouselIndicatorDots *self)
 {
@@ -89,7 +82,7 @@ animate (AdwCarouselIndicatorDots *self,
     adw_animation_stop (self->animation);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              value_cb,
+                                              gtk_widget_queue_draw,
                                               self, NULL);
   self->animation =
     adw_animation_new (GTK_WIDGET (self), 0, 1, duration, target);
diff --git a/src/adw-carousel-indicator-lines.c b/src/adw-carousel-indicator-lines.c
index c26c9831..d049ffd6 100644
--- a/src/adw-carousel-indicator-lines.c
+++ b/src/adw-carousel-indicator-lines.c
@@ -64,13 +64,6 @@ enum {
 
 static GParamSpec *props[LAST_PROP];
 
-static void
-value_cb (double     value,
-          GtkWidget *widget)
-{
-  gtk_widget_queue_draw (widget);
-}
-
 static void
 done_cb (AdwCarouselIndicatorLines *self)
 {
@@ -87,7 +80,7 @@ animate (AdwCarouselIndicatorLines *self,
     adw_animation_stop (self->animation);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              value_cb,
+                                              gtk_widget_queue_draw,
                                               self, NULL);
   self->animation =
     adw_animation_new (GTK_WIDGET (self), 0, 1, duration, target);
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index 2620c921..31488006 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 (double     value,
-                           ChildInfo *child)
+resize_animation_value_cb (ChildInfo *child,
+                           double     value)
 {
   AdwCarousel *self = ADW_CAROUSEL (adw_animation_get_widget (child->resize_animation));
   double delta = value - child->size;
@@ -346,8 +346,8 @@ shift_position (AdwCarousel *self,
 }
 
 static void
-scroll_animation_value_cb (double       value,
-                           AdwCarousel *self)
+scroll_animation_value_cb (AdwCarousel *self,
+                           double       value)
 {
   double position = adw_lerp (self->animation_source_position,
                               self->animation_target_child->snap_point,
diff --git a/src/adw-flap.c b/src/adw-flap.c
index 22afc919..fed54d7e 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -275,8 +275,8 @@ set_reveal_progress (AdwFlap *self,
 }
 
 static void
-fold_animation_value_cb (double   value,
-                         AdwFlap *self)
+fold_animation_value_cb (AdwFlap *self,
+                         double   value)
 {
   self->fold_progress = value;
 
@@ -315,13 +315,6 @@ animate_fold (AdwFlap *self)
   adw_animation_start (self->fold_animation);
 }
 
-static void
-reveal_animation_value_cb (double   value,
-                           AdwFlap *self)
-{
-  set_reveal_progress (self, value);
-}
-
 static void
 reveal_animation_done_cb (AdwFlap *self)
 {
@@ -347,7 +340,7 @@ animate_reveal (AdwFlap *self,
     adw_animation_stop (self->reveal_animation);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              reveal_animation_value_cb,
+                                              set_reveal_progress,
                                               self, NULL);
   self->reveal_animation =
     adw_animation_new (GTK_WIDGET (self), self->reveal_progress,
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index c77fb60e..0e13663f 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -770,13 +770,6 @@ adjustment_value_changed_cb (AdwTabBox *self)
   gtk_widget_queue_allocate (GTK_WIDGET (self));
 }
 
-static void
-scroll_animation_value_cb (double     value,
-                           GtkWidget *widget)
-{
-  gtk_widget_queue_resize (widget);
-}
-
 static void
 scroll_animation_done_cb (AdwTabBox *self)
 {
@@ -812,7 +805,7 @@ animate_scroll (AdwTabBox *self,
    */
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              scroll_animation_value_cb,
+                                              gtk_widget_queue_resize,
                                               self, NULL);
   self->scroll_animation =
     adw_animation_new (GTK_WIDGET (self), 0, 1, duration, target);
@@ -1006,8 +999,8 @@ get_reorder_position (AdwTabBox *self)
 }
 
 static void
-reorder_animation_value_cb (double   value,
-                            TabInfo *dest_tab)
+reorder_animation_value_cb (TabInfo *dest_tab,
+                            double   value)
 {
   GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (dest_tab->tab));
   AdwTabBox *self = ADW_TAB_BOX (parent);
@@ -1059,8 +1052,8 @@ animate_reordering (AdwTabBox *self,
 }
 
 static void
-reorder_offset_animation_value_cb (double   value,
-                                   TabInfo *info)
+reorder_offset_animation_value_cb (TabInfo *info,
+                                   double   value)
 {
   GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (info->tab));
 
@@ -1607,8 +1600,8 @@ extra_drag_drop_cb (AdwTab    *tab,
 }
 
 static void
-appear_animation_value_cb (double   value,
-                           TabInfo *info)
+appear_animation_value_cb (TabInfo *info,
+                           double   value)
 {
   info->appear_progress = value;
 
@@ -1916,12 +1909,12 @@ calculate_placeholder_index (AdwTabBox *self,
 }
 
 static void
-insert_animation_value_cb (double   value,
-                           TabInfo *info)
+insert_animation_value_cb (TabInfo *info,
+                           double   value)
 {
   AdwTabBox *self = ADW_TAB_BOX (gtk_widget_get_parent (GTK_WIDGET (info->tab)));
 
-  appear_animation_value_cb (value, info);
+  appear_animation_value_cb (info, value);
 
   update_drag_reodering (self);
 }
@@ -2279,8 +2272,8 @@ create_drag_icon (AdwTabBox *self,
 }
 
 static void
-icon_resize_animation_value_cb (double    value,
-                                DragIcon *icon)
+icon_resize_animation_value_cb (DragIcon *icon,
+                                double    value)
 {
   double relative_pos;
 
diff --git a/src/adw-tab.c b/src/adw-tab.c
index 83a7ebca..5454cb0a 100644
--- a/src/adw-tab.c
+++ b/src/adw-tab.c
@@ -88,8 +88,8 @@ set_style_class (GtkWidget  *widget,
 }
 
 static void
-close_btn_animation_value_cb (double  value,
-                              AdwTab *self)
+close_btn_animation_value_cb (AdwTab *self,
+                              double  value)
 {
   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 ce65f043..4c3b1120 100644
--- a/src/adw-toast-overlay.c
+++ b/src/adw-toast-overlay.c
@@ -120,8 +120,8 @@ dismiss_and_free_toast_info (ToastInfo *info)
 }
 
 static void
-hide_value_cb (double     value,
-               ToastInfo *info)
+hide_value_cb (ToastInfo *info,
+               double     value)
 {
   gtk_widget_set_opacity (info->widget, adw_ease_out_cubic (value));
 
@@ -149,13 +149,6 @@ hide_done_cb (ToastInfo *info)
   free_toast_info (info);
 }
 
-static void
-show_value_cb (double     value,
-               ToastInfo *info)
-{
-  gtk_widget_queue_allocate (GTK_WIDGET (info->overlay));
-}
-
 static void
 show_done_cb (ToastInfo *info)
 {
@@ -234,8 +227,8 @@ show_toast (AdwToastOverlay *self,
   gtk_widget_insert_before (info->widget, GTK_WIDGET (self), NULL);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
-                                              show_value_cb,
-                                              info, NULL);
+                                              gtk_widget_queue_allocate,
+                                              self, NULL);
   info->show_animation =
     adw_animation_new (GTK_WIDGET (self), 0, 1,
                        self->hiding_toasts ? REPLACE_DURATION : SHOW_DURATION,


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