[libadwaita/wip/exalm/spring-animation-swipes: 52/52] aaa




commit 4376418dda55d0740f240a09e4fc7dbc40f6d000
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Sat Dec 4 22:46:33 2021 +0500

    aaa

 src/adw-carousel.c         |  1 +
 src/adw-flap.c             | 66 +++++++++++++++++++++++++++++-----------------
 src/adw-leaflet.c          |  1 +
 src/adw-spring-animation.c |  6 ++---
 src/adw-swipe-tracker.c    |  7 ++---
 5 files changed, 51 insertions(+), 30 deletions(-)
---
diff --git a/src/adw-carousel.c b/src/adw-carousel.c
index fc09ba23..9f592b5c 100644
--- a/src/adw-carousel.c
+++ b/src/adw-carousel.c
@@ -423,6 +423,7 @@ static void
 end_swipe_cb (AdwSwipeTracker *tracker,
               guint            duration,
               double           to,
+              double           velocity,
               AdwCarousel     *self)
 {
   GtkWidget *child = get_page_at_position (self, to);
diff --git a/src/adw-flap.c b/src/adw-flap.c
index 5644e90b..6685b9cf 100644
--- a/src/adw-flap.c
+++ b/src/adw-flap.c
@@ -14,9 +14,9 @@
 #include "adw-gizmo-private.h"
 #include "adw-macros-private.h"
 #include "adw-shadow-helper-private.h"
+#include "adw-spring-animation.h"
 #include "adw-swipeable.h"
 #include "adw-swipe-tracker-private.h"
-#include "adw-timed-animation.h"
 #include "adw-widget-utils-private.h"
 
 /**
@@ -267,6 +267,7 @@ set_reveal_progress (AdwFlap *self,
                      double   progress)
 {
   self->reveal_progress = progress;
+  g_print ("reval %lf\n", progress);
 
   update_child_visibility (self);
   update_shield (self);
@@ -288,14 +289,19 @@ fold_animation_value_cb (AdwFlap *self,
 static void
 animate_fold (AdwFlap *self)
 {
-  adw_timed_animation_set_value_from (ADW_TIMED_ANIMATION (self->fold_animation),
-                                      self->fold_progress);
-  adw_timed_animation_set_value_to (ADW_TIMED_ANIMATION (self->fold_animation),
-                                    self->folded ? 1 : 0);
+  if (self->reveal_progress <= 0) {
+    fold_animation_value_cb (self, self->folded ? 1 : 0);
+    return;
+  }
+
+  adw_spring_animation_set_value_from (ADW_SPRING_ANIMATION (self->fold_animation),
+                                     self->fold_progress);
+  adw_spring_animation_set_value_to (ADW_SPRING_ANIMATION (self->fold_animation),
+                                     self->folded ? 1 : 0);
 
   /* When the flap is completely hidden, we can skip animation */
-  adw_timed_animation_set_duration (ADW_TIMED_ANIMATION (self->fold_animation),
-                             (self->reveal_progress > 0) ? self->fold_duration : 0);
+//  adw_timed_animation_set_duration (ADW_TIMED_ANIMATION (self->fold_animation),
+//                                    self->fold_duration);
 
   adw_animation_play (self->fold_animation);
 }
@@ -315,14 +321,18 @@ reveal_animation_done_cb (AdwFlap *self)
 static void
 animate_reveal (AdwFlap *self,
                 double   to,
-                guint    duration)
+                double   velocity)
 {
-  adw_timed_animation_set_value_from (ADW_TIMED_ANIMATION (self->reveal_animation),
-                                      self->reveal_progress);
-  adw_timed_animation_set_value_to (ADW_TIMED_ANIMATION (self->reveal_animation),
-                                    to);
-  adw_timed_animation_set_duration (ADW_TIMED_ANIMATION (self->reveal_animation),
-                                    duration);
+  adw_spring_animation_set_value_from (ADW_SPRING_ANIMATION (self->reveal_animation),
+                                       self->reveal_progress);
+  adw_spring_animation_set_value_to (ADW_SPRING_ANIMATION (self->reveal_animation),
+                                     to);
+//  adw_timed_animation_set_duration (ADW_TIMED_ANIMATION (self->reveal_animation),
+//                                    duration);
+
+  adw_spring_animation_set_initial_velocity (ADW_SPRING_ANIMATION (self->reveal_animation),
+                                             velocity);
+  g_print ("WTF %lf\n", velocity);
 
   adw_animation_play (self->reveal_animation);
 }
@@ -330,7 +340,7 @@ animate_reveal (AdwFlap *self,
 static void
 set_reveal_flap (AdwFlap  *self,
                  gboolean  reveal_flap,
-                 guint     duration)
+                 double    velocity)
 {
   reveal_flap = !!reveal_flap;
 
@@ -340,7 +350,7 @@ set_reveal_flap (AdwFlap  *self,
   self->reveal_flap = reveal_flap;
 
   if (!self->swipe_active)
-    animate_reveal (self, reveal_flap ? 1 : 0, duration);
+    animate_reveal (self, reveal_flap ? 1 : 0, velocity);
 
   g_object_notify_by_pspec (G_OBJECT (self), props[PROP_REVEAL_FLAP]);
 }
@@ -370,7 +380,7 @@ set_folded (AdwFlap  *self,
     animate_fold (self);
 
   if (!self->locked)
-    set_reveal_flap (self, !self->folded, self->fold_duration);
+    set_reveal_flap (self, !self->folded, 0);
 
   context = gtk_widget_get_style_context (GTK_WIDGET (self));
   if (folded) {
@@ -420,6 +430,7 @@ update_swipe_cb (AdwSwipeTracker *tracker,
 static void
 end_swipe_cb (AdwSwipeTracker *tracker,
               guint            duration,
+              double           velocity,
               double           to,
               AdwFlap         *self)
 {
@@ -429,9 +440,9 @@ end_swipe_cb (AdwSwipeTracker *tracker,
   self->swipe_active = FALSE;
 
   if ((to > 0) == self->reveal_flap)
-    animate_reveal (self, to, duration);
+    animate_reveal (self, to, velocity);
   else
-    set_reveal_flap (self, to > 0, duration);
+    set_reveal_flap (self, to > 0, velocity);
 }
 
 static void
@@ -756,6 +767,8 @@ compute_allocation (AdwFlap       *self,
 
   interpolate_fold (self, width, height, &flap_size, &content_size, &separator_size);
 
+  flap_size = (int) ceil (flap_size * MAX (self->reveal_progress, 1));
+
   if (self->orientation == GTK_ORIENTATION_HORIZONTAL) {
     flap_alloc->width = flap_size;
     content_alloc->width = content_size;
@@ -778,14 +791,17 @@ compute_allocation (AdwFlap       *self,
   else
     distance = flap_size + separator_size * (1 - self->fold_progress);
 
-  flap_pos = -(int) round ((1 - self->reveal_progress) * transition_get_flap_motion_factor (self) * 
distance);
+  flap_pos = -(int) round ((1 - MIN (self->reveal_progress, 1)) * transition_get_flap_motion_factor (self) * 
distance);
 
   if (content_above_flap) {
     content_pos = (int) round (self->reveal_progress * transition_get_content_motion_factor (self) * 
distance);
     separator_pos = flap_pos + flap_size;
   } else {
     content_pos = total - content_size + (int) round (self->reveal_progress * self->fold_progress * 
transition_get_content_motion_factor (self) * distance);
-    separator_pos = content_pos - separator_size;
+    if (self->reveal_progress > 1)
+      separator_pos = flap_pos + flap_size;
+    else
+      separator_pos = content_pos - separator_size;
   }
 
   if (self->flap_position != get_start_or_end (self)) {
@@ -1603,13 +1619,15 @@ adw_flap_init (AdwFlap *self)
                                               fold_animation_value_cb,
                                               self, NULL);
   self->fold_animation =
-    adw_timed_animation_new (GTK_WIDGET (self), 0, 0, 0, target);
+    adw_spring_animation_new (GTK_WIDGET (self), 0, 0,
+                              adw_spring_params_new (0.9, 1, 100), target);
 
   target = adw_callback_animation_target_new ((AdwAnimationTargetFunc)
                                               set_reveal_progress,
                                               self, NULL);
   self->reveal_animation =
-    adw_timed_animation_new (GTK_WIDGET (self), 0, 0, 0, target);
+    adw_spring_animation_new (GTK_WIDGET (self), 0, 0,
+                             adw_spring_params_new_full (10, 1, 100), target);
 
   g_signal_connect_swapped (self->reveal_animation, "done",
                             G_CALLBACK (reveal_animation_done_cb), self);
@@ -2043,7 +2061,7 @@ adw_flap_set_reveal_flap (AdwFlap  *self,
 {
   g_return_if_fail (ADW_IS_FLAP (self));
 
-  set_reveal_flap (self, reveal_flap, self->reveal_duration);
+  set_reveal_flap (self, reveal_flap, 0);
 }
 
 /**
diff --git a/src/adw-leaflet.c b/src/adw-leaflet.c
index fa999e44..fc4dbcd8 100644
--- a/src/adw-leaflet.c
+++ b/src/adw-leaflet.c
@@ -1605,6 +1605,7 @@ update_swipe_cb (AdwSwipeTracker *tracker,
 static void
 end_swipe_cb (AdwSwipeTracker *tracker,
               guint            duration,
+              double           velocity,
               double           to,
               AdwLeaflet      *self)
 {
diff --git a/src/adw-spring-animation.c b/src/adw-spring-animation.c
index ef1bcbfd..8737c0cd 100644
--- a/src/adw-spring-animation.c
+++ b/src/adw-spring-animation.c
@@ -67,7 +67,7 @@ oscillate (AdwAnimation *animation,
   double b = adw_spring_params_get_damping (self->spring_params);
   double m = adw_spring_params_get_mass (self->spring_params);
   double k = adw_spring_params_get_stiffness (self->spring_params);
-  double v0 = self->initial_velocity;
+  double v0 = self->initial_velocity / (self->value_to - self->value_from);
 
   double t = time / 1000.0;
 
@@ -369,8 +369,8 @@ adw_spring_animation_new (GtkWidget          *widget,
                             "spring-params", spring_params,
                             "target", target,
                             NULL);
-  g_object_unref (target);
-  adw_spring_params_unref (spring_params);
+//  g_object_unref (target);
+//  adw_spring_params_unref (spring_params);
 
   return animation;
 }
diff --git a/src/adw-swipe-tracker.c b/src/adw-swipe-tracker.c
index 543e17c3..c4b4fc44 100644
--- a/src/adw-swipe-tracker.c
+++ b/src/adw-swipe-tracker.c
@@ -448,7 +448,7 @@ gesture_end (AdwSwipeTracker *self,
   if (self->progress != end_progress)
     duration = CLAMP (duration, MIN_ANIMATION_DURATION, max_duration);
 
-  g_signal_emit (self, signals[SIGNAL_END_SWIPE], 0, duration, end_progress);
+  g_signal_emit (self, signals[SIGNAL_END_SWIPE], 0, duration, calculate_velocity (self) / distance, 
end_progress);
 
   if (!self->cancelled)
     self->state = ADW_SWIPE_TRACKER_STATE_FINISHING;
@@ -1152,6 +1152,7 @@ adw_swipe_tracker_class_init (AdwSwipeTrackerClass *klass)
    * AdwSwipeTracker::end-swipe:
    * @self: the `AdwSwipeTracker` instance
    * @duration: snap-back animation duration in milliseconds
+   * @velocity: velocity of the gesture
    * @to: the progress value to animate to
    *
    * This signal is emitted as soon as the gesture has stopped.
@@ -1165,8 +1166,8 @@ adw_swipe_tracker_class_init (AdwSwipeTrackerClass *klass)
                   0,
                   NULL, NULL, NULL,
                   G_TYPE_NONE,
-                  2,
-                  G_TYPE_UINT, G_TYPE_DOUBLE);
+                  3,
+                  G_TYPE_UINT, G_TYPE_DOUBLE, G_TYPE_DOUBLE);
 }
 
 static void


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