[libadwaita/wip/exalm/animation-cleanups: 3/8] easing: Add adw_easing_ease()
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/animation-cleanups: 3/8] easing: Add adw_easing_ease()
- Date: Mon, 22 Nov 2021 16:06:48 +0000 (UTC)
commit f3bb485393074c10a0b953291cac62141bddd065
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Nov 22 18:49:09 2021 +0500
easing: Add adw_easing_ease()
Have a public function for actually using easings outside timed animations
as well.
src/adw-easing.c | 31 +++++++++++++++++++++++++++++++
src/adw-easing.h | 4 ++++
src/adw-timed-animation.c | 14 +-------------
3 files changed, 36 insertions(+), 13 deletions(-)
---
diff --git a/src/adw-easing.c b/src/adw-easing.c
index 94be65e6..702774c2 100644
--- a/src/adw-easing.c
+++ b/src/adw-easing.c
@@ -8,6 +8,8 @@
#include "adw-easing.h"
+#include "adw-animation-util-private.h"
+
/**
* AdwEasing:
* @ADW_EASING_EASE_IN_CUBIC: Starts slowly and accelerates, cubic curve.
@@ -24,3 +26,32 @@
*
* Since: 1.0
*/
+
+/**
+ * adw_easing_ease:
+ * @self: a `AdwEasing`
+ * @value: a value to ease
+ *
+ * Computes easing with @easing for @value.
+ *
+ * @value should generally be in the [0, 1] range.
+ *
+ * Returns: the easing for @value
+ *
+ * Since: 1.0
+ */
+double
+adw_easing_ease (AdwEasing self,
+ double value)
+{
+ switch (self) {
+ case ADW_EASING_EASE_IN_CUBIC:
+ return adw_ease_in_cubic (value);
+ case ADW_EASING_EASE_OUT_CUBIC:
+ return adw_ease_out_cubic (value);
+ case ADW_EASING_EASE_IN_OUT_CUBIC:
+ return adw_ease_in_out_cubic (value);
+ default:
+ g_assert_not_reached ();
+ }
+}
diff --git a/src/adw-easing.h b/src/adw-easing.h
index 5dc640b5..39155eb0 100644
--- a/src/adw-easing.h
+++ b/src/adw-easing.h
@@ -24,4 +24,8 @@ typedef enum {
ADW_EASING_EASE_IN_OUT_CUBIC,
} AdwEasing;
+ADW_AVAILABLE_IN_ALL
+double adw_easing_ease (AdwEasing self,
+ double value);
+
G_END_DECLS
diff --git a/src/adw-timed-animation.c b/src/adw-timed-animation.c
index b40fc6f7..d4382bbb 100644
--- a/src/adw-timed-animation.c
+++ b/src/adw-timed-animation.c
@@ -110,19 +110,7 @@ adw_timed_animation_calculate_value (AdwAnimation *animation,
progress = reverse ? (1 - progress) : progress;
- switch (self->easing) {
- case ADW_EASING_EASE_IN_CUBIC:
- value = adw_ease_in_cubic (progress);
- break;
- case ADW_EASING_EASE_OUT_CUBIC:
- value = adw_ease_out_cubic (progress);
- break;
- case ADW_EASING_EASE_IN_OUT_CUBIC:
- value = adw_ease_in_out_cubic (progress);
- break;
- default:
- g_assert_not_reached ();
- }
+ value = adw_easing_ease (self->easing, progress);
return adw_lerp (self->value_from, self->value_to, value);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]