Skip to content

Commit b64e244

Browse files
committed
transition: remove unused functions
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
1 parent 7169193 commit b64e244

File tree

2 files changed

+1
-213
lines changed

2 files changed

+1
-213
lines changed

src/transition.c

-126
Original file line numberDiff line numberDiff line change
@@ -10,132 +10,6 @@
1010
#include "transition.h"
1111
#include "utils.h"
1212

13-
double animatable_get_progress(const struct animatable *a) {
14-
if (a->duration > 0) {
15-
return a->elapsed / a->duration;
16-
}
17-
return 1;
18-
}
19-
20-
/// Get the current value of an `animatable`.
21-
double animatable_get(const struct animatable *a) {
22-
if (a->duration > 0) {
23-
assert(a->elapsed < a->duration);
24-
double t = a->curve->sample(a->curve, animatable_get_progress(a));
25-
return (1 - t) * a->start + t * a->target;
26-
}
27-
return a->target;
28-
}
29-
30-
/// Advance the animation by a given number of steps.
31-
void animatable_advance(struct animatable *a, double elapsed) {
32-
if (a->duration == 0 || elapsed <= 0) {
33-
return;
34-
}
35-
36-
assert(a->elapsed < a->duration);
37-
if (elapsed >= a->duration - a->elapsed) {
38-
a->elapsed = a->duration;
39-
} else {
40-
a->elapsed += elapsed;
41-
}
42-
43-
if (a->elapsed == a->duration) {
44-
a->start = a->target;
45-
a->duration = 0;
46-
a->elapsed = 0;
47-
a->curve->free(a->curve);
48-
a->curve = NULL;
49-
if (a->callback) {
50-
a->callback(TRANSITION_COMPLETED, a->callback_data);
51-
a->callback = NULL;
52-
a->callback_data = NULL;
53-
}
54-
}
55-
}
56-
57-
/// Returns whether an `animatable` is currently animating.
58-
bool animatable_is_animating(const struct animatable *a) {
59-
assert(a->duration == 0 || a->elapsed < a->duration);
60-
return a->duration != 0;
61-
}
62-
63-
/// Cancel the current animation of an `animatable`. This stops the animation and
64-
/// the `animatable` will retain its current value.
65-
///
66-
/// Returns true if the `animatable` was animated before this function is called.
67-
bool animatable_interrupt(struct animatable *a) {
68-
if (a->duration == 0) {
69-
return false;
70-
}
71-
72-
a->start = animatable_get(a);
73-
a->target = a->start;
74-
a->duration = 0;
75-
a->elapsed = 0;
76-
a->curve->free(a->curve);
77-
a->curve = NULL;
78-
if (a->callback) {
79-
a->callback(TRANSITION_INTERRUPTED, a->callback_data);
80-
a->callback = NULL;
81-
a->callback_data = NULL;
82-
}
83-
return true;
84-
}
85-
86-
/// Cancel the current animation of an `animatable` and set its value to its target.
87-
///
88-
/// Returns true if the `animatable` was animated before this function is called.
89-
bool animatable_skip(struct animatable *a) {
90-
if (a->duration == 0) {
91-
return false;
92-
}
93-
94-
a->start = a->target;
95-
a->duration = 0;
96-
a->elapsed = 0;
97-
a->curve->free(a->curve);
98-
a->curve = NULL;
99-
if (a->callback) {
100-
a->callback(TRANSITION_SKIPPED, a->callback_data);
101-
a->callback = NULL;
102-
a->callback_data = NULL;
103-
}
104-
return true;
105-
}
106-
107-
/// Change the target value of an `animatable`.
108-
/// If the `animatable` is already animating, the animation will be canceled first.
109-
bool animatable_set_target(struct animatable *a, double target, double duration,
110-
const struct curve *curve, transition_callback_fn cb, void *data) {
111-
animatable_interrupt(a);
112-
if (duration == 0 || a->start == target) {
113-
a->start = target;
114-
a->target = target;
115-
curve->free(curve);
116-
return false;
117-
}
118-
119-
a->target = target;
120-
a->duration = duration;
121-
a->elapsed = 0;
122-
a->callback = cb;
123-
a->callback_data = data;
124-
a->curve = curve;
125-
return true;
126-
}
127-
128-
/// Create a new animatable.
129-
struct animatable animatable_new(double value) {
130-
struct animatable ret = {
131-
.start = value,
132-
.target = value,
133-
.duration = 0,
134-
.elapsed = 0,
135-
};
136-
return ret;
137-
}
138-
13913
static double curve_sample_linear(const struct curve *this attr_unused, double progress) {
14014
return progress;
14115
}

src/transition.h

+1-87
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,7 @@
55
#include <stdbool.h>
66
#include "compiler.h"
77

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 ==========================
339

3410
struct curve {
3511
/// The interpolator function for an animatable. This function should calculate
@@ -40,68 +16,6 @@ struct curve {
4016
void (*free)(const struct curve *this);
4117
};
4218

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-
10519
const struct curve *curve_new_linear(void);
10620
const struct curve *curve_new_cubic_bezier(double x1, double y1, double x2, double y2);
10721
const struct curve *curve_new_step(int steps, bool jump_start, bool jump_end);

0 commit comments

Comments
 (0)