1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Ranim's built-in animations
//!
//! This crate contains the built-in animations for Ranim.
//!
//! An **Animation** in ranim is basically a struct that implements the [`ranim_core::animation::EvalDynamic`] trait:
//!
//! ```rust,ignore
//! pub trait EvalDynamic<T> {
//! /// Evaluates at the given progress value `alpha` in range [0, 1].
//! fn eval_alpha(&self, alpha: f64) -> T;
//! }
//! ```
//!
//! Every animation self-contains the evaluation process (the trait impl of [`ranim_core::animation::EvalDynamic::eval_alpha`])
//! and the data that the evaluation process needs (the struct it self). Here is the example of [`fading::FadeIn`] animation:
//!
//! ```rust,ignore
//! pub trait FadingRequirement: Opacity + Interpolatable + Clone {}
//! impl<T: Opacity + Interpolatable + Clone> FadingRequirement for T {}
//!
//! pub struct FadeIn<T: FadingRequirement> {
//! src: T,
//! dst: T,
//! }
//!
//! impl<T: FadingRequirement> FadeIn<T> {
//! pub fn new(target: T) -> Self {
//! let mut src = target.clone();
//! let dst = target.clone();
//! src.set_opacity(0.0);
//! Self { src, dst }
//! }
//! }
//!
//! impl<T: FadingRequirement> EvalDynamic<T> for FadeIn<T> {
//! fn eval_alpha(&self, alpha: f64) -> T {
//! self.src.lerp(&self.dst, alpha)
//! }
//! }
//! ```
//!
//! In addition, to make the construction of anim for any type that satisfies the requirement,
//! It is recommended to write a trait like this:
//!
//! ```rust,ignore
//! /// The methods to create animations for `T` that satisfies [`FadingRequirement`]
//! pub trait FadingAnim<T: FadingRequirement + 'static> {
//! fn fade_in(self) -> AnimationSpan<T>;
//! fn fade_out(self) -> AnimationSpan<T>;
//! }
//!
//! impl<T: FadingRequirement + 'static> FadingAnim<T> for T {
//! fn fade_in(self) -> AnimationSpan<T> {
//! FadeIn::new(self.clone())
//! .into_animation_span()
//! .with_rate_func(smooth)
//! }
//! fn fade_out(self) -> AnimationSpan<T> {
//! FadeOut::new(self.clone())
//! .into_animation_span()
//! .with_rate_func(smooth)
//! }
//! }
//! ```
/// Creation animation
/// Fading animation
/// Func animation
/// Lagged animation
/// Transform animation