[libadwaita/wip/exalm/animation-cleanups: 4/8] easing: Move the easing functions from animation utils
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/animation-cleanups: 4/8] easing: Move the easing functions from animation utils
- Date: Mon, 22 Nov 2021 16:06:48 +0000 (UTC)
commit d95918c3625c19dd9628fccf1a1ac6b97187116e
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Nov 22 19:07:49 2021 +0500
easing: Move the easing functions from animation utils
Make them static, recommend using adw_easing_ease().
doc/migrating-between-development-versions.md | 6 ++++
doc/migrating-libhandy-1-4-to-libadwaita.md | 6 ++++
src/adw-animation-util-private.h | 3 --
src/adw-animation-util.c | 41 ---------------------------
src/adw-animation-util.h | 3 --
src/adw-clamp-layout.c | 5 ++--
src/adw-easing.c | 38 +++++++++++++++++++++----
src/adw-tab-box.c | 5 +++-
src/adw-toast-overlay.c | 4 ++-
src/gtkprogresstracker.c | 4 +--
10 files changed, 56 insertions(+), 59 deletions(-)
---
diff --git a/doc/migrating-between-development-versions.md b/doc/migrating-between-development-versions.md
index faee4532..898645f8 100644
--- a/doc/migrating-between-development-versions.md
+++ b/doc/migrating-between-development-versions.md
@@ -304,6 +304,12 @@ swipes.
The type of the `duration` parameter in [method@Adw.Carousel.scroll_to_full] has
changed from `gint64` to `guint`.
+### Adapt to Miscellaneous Changes
+
+The `adw_ease_out_cubic()` function has been removed. Instead,
+[func Adw Easing ease] can be used with the `ADW_EASING_EASE_OUT_CUBIC`
+parameter.
+
### Adapt to Stylesheet Changes
### Adapt to the `button.outline` style removal
diff --git a/doc/migrating-libhandy-1-4-to-libadwaita.md b/doc/migrating-libhandy-1-4-to-libadwaita.md
index 6d4fb98a..899df7d9 100644
--- a/doc/migrating-libhandy-1-4-to-libadwaita.md
+++ b/doc/migrating-libhandy-1-4-to-libadwaita.md
@@ -360,6 +360,12 @@ swipes.
The type of the `duration` parameter in [method@Adw.Carousel.scroll_to_full] has
changed from `gint64` to `guint`.
+### Adapt to Miscellaneous Changes
+
+The `hdy_ease_out_cubic()` function has been removed. Instead,
+[func Adw Easing ease] can be used with the `ADW_EASING_EASE_OUT_CUBIC`
+parameter.
+
### Adapt to Stylesheet Changes
Most widgets don't have a backdrop state anymore, and the following public
diff --git a/src/adw-animation-util-private.h b/src/adw-animation-util-private.h
index 5ebf2a7a..e4eeb428 100644
--- a/src/adw-animation-util-private.h
+++ b/src/adw-animation-util-private.h
@@ -16,9 +16,6 @@
G_BEGIN_DECLS
-double adw_ease_in_cubic (double t);
-double adw_ease_in_out_cubic (double t);
-
double adw_lerp (double a,
double b,
double t);
diff --git a/src/adw-animation-util.c b/src/adw-animation-util.c
index 8228249a..65bb1097 100644
--- a/src/adw-animation-util.c
+++ b/src/adw-animation-util.c
@@ -27,47 +27,6 @@ adw_lerp (double a, double b, double t)
return a * (1.0 - t) + b * t;
}
-/* From clutter-easing.c, based on Robert Penner's
- * infamous easing equations, MIT license.
- */
-
-/**
- * adw_ease_out_cubic:
- * @t: the term
- *
- * Computes the ease out for @t.
- *
- * Returns: the ease out for @t
- *
- * Since: 1.0
- */
-
-double
-adw_ease_out_cubic (double t)
-{
- double p = t - 1;
- return p * p * p + 1;
-}
-
-double
-adw_ease_in_cubic (gdouble t)
-{
- return t * t * t;
-}
-
-double
-adw_ease_in_out_cubic (double t)
-{
- double p = t * 2;
-
- if (p < 1)
- return 0.5 * p * p * p;
-
- p -= 2;
-
- return 0.5 * (p * p * p + 2);
-}
-
/**
* adw_get_enable_animations:
* @widget: a `GtkWidget`
diff --git a/src/adw-animation-util.h b/src/adw-animation-util.h
index e97a2e88..02f5cf91 100644
--- a/src/adw-animation-util.h
+++ b/src/adw-animation-util.h
@@ -17,9 +17,6 @@
G_BEGIN_DECLS
-ADW_AVAILABLE_IN_ALL
-double adw_ease_out_cubic (double t);
-
ADW_AVAILABLE_IN_ALL
gboolean adw_get_enable_animations (GtkWidget *widget);
diff --git a/src/adw-clamp-layout.c b/src/adw-clamp-layout.c
index 0a1833de..3d5431d8 100644
--- a/src/adw-clamp-layout.c
+++ b/src/adw-clamp-layout.c
@@ -9,8 +9,7 @@
#include <math.h>
-#include "adw-animation-util.h"
-#include "adw-animation-private.h"
+#include "adw-easing.h"
#include "adw-macros-private.h"
/**
@@ -161,7 +160,7 @@ get_child_size (AdwClampLayout *self,
progress = (double) (for_size - lower) / (double) (upper - lower);
- return adw_ease_out_cubic (progress) * amplitude + lower;
+ return adw_easing_ease (ADW_EASING_EASE_OUT_CUBIC, progress) * amplitude + lower;
}
static GtkSizeRequestMode
diff --git a/src/adw-easing.c b/src/adw-easing.c
index 702774c2..b62db4d6 100644
--- a/src/adw-easing.c
+++ b/src/adw-easing.c
@@ -8,8 +8,6 @@
#include "adw-easing.h"
-#include "adw-animation-util-private.h"
-
/**
* AdwEasing:
* @ADW_EASING_EASE_IN_CUBIC: Starts slowly and accelerates, cubic curve.
@@ -27,6 +25,36 @@
* Since: 1.0
*/
+/* From clutter-easing.c, based on Robert Penner's
+ * infamous easing equations, MIT license.
+ */
+
+static inline double
+ease_out_cubic (double t)
+{
+ double p = t - 1;
+ return p * p * p + 1;
+}
+
+static inline double
+ease_in_cubic (gdouble t)
+{
+ return t * t * t;
+}
+
+static inline double
+ease_in_out_cubic (double t)
+{
+ double p = t * 2;
+
+ if (p < 1)
+ return 0.5 * p * p * p;
+
+ p -= 2;
+
+ return 0.5 * (p * p * p + 2);
+}
+
/**
* adw_easing_ease:
* @self: a `AdwEasing`
@@ -46,11 +74,11 @@ adw_easing_ease (AdwEasing self,
{
switch (self) {
case ADW_EASING_EASE_IN_CUBIC:
- return adw_ease_in_cubic (value);
+ return ease_in_cubic (value);
case ADW_EASING_EASE_OUT_CUBIC:
- return adw_ease_out_cubic (value);
+ return ease_out_cubic (value);
case ADW_EASING_EASE_IN_OUT_CUBIC:
- return adw_ease_in_out_cubic (value);
+ return ease_in_out_cubic (value);
default:
g_assert_not_reached ();
}
diff --git a/src/adw-tab-box.c b/src/adw-tab-box.c
index 5383d6aa..73b245c1 100644
--- a/src/adw-tab-box.c
+++ b/src/adw-tab-box.c
@@ -9,7 +9,9 @@
#include "config.h"
#include "adw-tab-box-private.h"
+
#include "adw-animation-util-private.h"
+#include "adw-easing.h"
#include "adw-gizmo-private.h"
#include "adw-macros-private.h"
#include "adw-tab-private.h"
@@ -1258,7 +1260,8 @@ drag_autoscroll_cb (GtkWidget *widget,
autoscroll_factor = (x - end_threshold) / autoscroll_area;
autoscroll_factor = CLAMP (autoscroll_factor, -1, 1);
- autoscroll_factor = adw_ease_in_cubic (autoscroll_factor);
+ autoscroll_factor = adw_easing_ease (ADW_EASING_EASE_IN_CUBIC,
+ autoscroll_factor);
self->drag_autoscroll_prev_time = time;
if (autoscroll_factor == 0)
diff --git a/src/adw-toast-overlay.c b/src/adw-toast-overlay.c
index 081c98e2..162717e6 100644
--- a/src/adw-toast-overlay.c
+++ b/src/adw-toast-overlay.c
@@ -9,6 +9,7 @@
#include "adw-toast-overlay.h"
#include "adw-animation-util-private.h"
+#include "adw-easing.h"
#include "adw-macros-private.h"
#include "adw-timed-animation.h"
#include "adw-toast-private.h"
@@ -123,7 +124,8 @@ static void
hide_value_cb (ToastInfo *info,
double value)
{
- gtk_widget_set_opacity (info->widget, adw_ease_out_cubic (value));
+ value = adw_easing_ease (ADW_EASING_EASE_OUT_CUBIC, value);
+ gtk_widget_set_opacity (info->widget, value);
gtk_widget_queue_allocate (GTK_WIDGET (info->overlay));
}
diff --git a/src/gtkprogresstracker.c b/src/gtkprogresstracker.c
index 1f32edfc..0339cdd2 100644
--- a/src/gtkprogresstracker.c
+++ b/src/gtkprogresstracker.c
@@ -24,7 +24,7 @@
#include <math.h>
#include <string.h>
-#include "adw-animation-util.h"
+#include "adw-easing.h"
/*
* Progress tracker is small helper for tracking progress through gtk
@@ -244,5 +244,5 @@ gtk_progress_tracker_get_ease_out_cubic (GtkProgressTracker *tracker,
gboolean reversed)
{
double progress = gtk_progress_tracker_get_progress (tracker, reversed);
- return adw_ease_out_cubic (progress);
+ return adw_easing_ease (ADW_EASING_EASE_OUT_CUBIC, progress);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]