5
5
#include <stdbool.h>
6
6
#include "compiler.h"
7
7
8
- struct animatable ;
9
- enum transition_event ;
10
-
11
- /// Callback when the transition state changes. Callback might be called by:
12
- /// - `animatable_set_target` generates TRANSITION_COMPLETED when the specified duration
13
- /// is 0. also generates TRANSITION_CANCELLED if the animatable was already animating.
14
- /// - `animatable_cancel` generates TRANSITION_CANCELED
15
- /// - `animatable_early_stop` generates TRANSITION_STOPPED_EARLY
16
- /// - `animatable_step` generates TRANSITION_COMPLETED when the animation is completed.
17
- /// Callback is guaranteed to be called exactly once for each `animatable_set_target`
18
- /// call, unless an animatable is freed before the transition is completed.
19
- typedef void (* transition_callback_fn )(enum transition_event event , void * data );
20
-
21
- enum transition_event {
22
- TRANSITION_COMPLETED ,
23
- TRANSITION_INTERRUPTED ,
24
- TRANSITION_SKIPPED ,
25
- };
26
-
27
- /// The base type for step_state.
28
- struct step_state_base {
29
- /// The current value of the `animatable`.
30
- /// If the `animatable` is not animated, this equals to `animatable->target`.
31
- double current ;
32
- };
8
+ // ========================== Interpolators ==========================
33
9
34
10
struct curve {
35
11
/// The interpolator function for an animatable. This function should calculate
@@ -40,68 +16,6 @@ struct curve {
40
16
void (* free )(const struct curve * this );
41
17
};
42
18
43
- /// An animatable value
44
- struct animatable {
45
- /// The starting value.
46
- /// When this `animatable` is not animated, this is the current value.
47
- double start ;
48
- /// The target value.
49
- /// If the `animatable` is not animated, this equals to `start`.
50
- double target ;
51
- /// The animation duration in unspecified units.
52
- /// If the `animatable` is not animated, this is 0.
53
- double duration ;
54
- /// The current progress of the animation in the same units as `duration`.
55
- /// If the `animatable` is not animated, this is 0.
56
- double elapsed ;
57
-
58
- transition_callback_fn callback ;
59
- void * callback_data ;
60
-
61
- /// The function for calculating the current value. If
62
- /// `step_state` is not NULL, the `step` function is used;
63
- /// otherwise, the `interpolator` function is used.
64
- /// The interpolator function.
65
- const struct curve * curve ;
66
- };
67
-
68
- // =============================== API ===============================
69
-
70
- /// Get the current value of an `animatable`.
71
- double animatable_get (const struct animatable * a );
72
- /// Get the animation progress as a percentage of the total duration.
73
- double animatable_get_progress (const struct animatable * a );
74
- /// Advance the animation by a given amount. `elapsed` cannot be negative.
75
- void animatable_advance (struct animatable * a , double elapsed );
76
- /// Returns whether an `animatable` is currently animating.
77
- bool animatable_is_animating (const struct animatable * a );
78
- /// Interrupt the current animation of an `animatable`. This stops the animation and
79
- /// the `animatable` will retain its current value.
80
- ///
81
- /// Returns true if the `animatable` was animated before this function is called.
82
- bool animatable_interrupt (struct animatable * a );
83
- /// Skip the current animation of an `animatable` and set its value to its target.
84
- ///
85
- /// Returns true if the `animatable` was animated before this function is called.
86
- bool animatable_skip (struct animatable * a );
87
- /// Change the target value of an `animatable`. Specify a duration, an interpolator
88
- /// function, and a callback function.
89
- ///
90
- /// If the `animatable` is already animating, the animation will be canceled first.
91
- ///
92
- /// Note, In some cases this function does not start the animation, for example, if the
93
- /// target value is the same as the current value of the animatable, or if the duration is
94
- /// 0. If the animation is not started, the callback function will not be called. The
95
- /// animatable's current animation, if it has one, will be canceled regardless.
96
- ///
97
- /// Returns if the animatable is now animated.
98
- bool animatable_set_target (struct animatable * a , double target , double duration ,
99
- const struct curve * curve , transition_callback_fn cb , void * data );
100
- /// Create a new animatable.
101
- struct animatable animatable_new (double value );
102
-
103
- // ========================== Interpolators ==========================
104
-
105
19
const struct curve * curve_new_linear (void );
106
20
const struct curve * curve_new_cubic_bezier (double x1 , double y1 , double x2 , double y2 );
107
21
const struct curve * curve_new_step (int steps , bool jump_start , bool jump_end );
0 commit comments