66 std::function<void(
Layout *, T)> setter;
70 : start_val(s), end_val(e), setter(std::move(setter)), transition(tr) {}
74 float ratio =
getRatio(raw_t, transition);
75 setter(target, lerpProp(start_val, end_val, ratio));
79 UIAnimation(
float duration = 1.0f,
float delay = 0.0f)
80 : duration(duration), delay(delay) {}
83 template <
typename T,
typename Callable>
86 tracks.push_back(std::make_unique<
Track<T>>(start, end, std::function<
void(
Layout *, T)>(setter), tr));
91 bool blocksInput{
true};
92 std::vector<std::unique_ptr<TrackBase>> tracks;
93 std::function<void()> onFinished;
99 std::shared_ptr<UIAnimation> anim;
101 float delayElapsed{0.0f};
117 std::vector<Keyframe> keyframes;
125 double startTime{0.0};
126 float duration{1.0f};
129 bool alternate{
false};
130 bool fillForwards{
false};
131 bool finished{
false};
134 mutable float cachedSampleElapsed{-1.0f};
135 mutable float cachedLocalT{0.0f};
136 mutable bool cachedFinished{
false};
153 float t = a.elapsed - a.delay;
156 if (a.duration <= 0.0f)
162 float total = (a.iterations < 0) ? -1.0f : (a.duration * (float)a.iterations);
163 if (a.iterations >= 0 && t >= total)
168 float iter = std::floor(t / a.duration);
170 if (a.iterations > 0 && finished && iter > 0.0f)
172 iter = std::min(iter, (
float)(a.iterations - 1));
175 float local = (t - iter * a.duration) / a.duration;
176 if (a.alternate && ((
int)iter % 2 == 1))
177 local = 1.0f - local;
178 return std::clamp(local, 0.0f, 1.0f);
186 if (a.cachedSampleElapsed == a.elapsed)
188 finished = a.cachedFinished;
189 return a.cachedLocalT;
193 a.cachedFinished = finished;
194 a.cachedSampleElapsed = a.elapsed;
195 return a.cachedLocalT;
209 if (anim.keyframes.empty())
211 if (anim.keyframes.size() == 1)
212 return anim.keyframes[0].delta;
214 const Keyframe *k0 = &anim.keyframes.front();
215 const Keyframe *k1 = &anim.keyframes.back();
216 for (
size_t i = 0; i + 1 < anim.keyframes.size(); ++i)
218 if (localT >= anim.keyframes[i].t && localT <= anim.keyframes[i + 1].t)
220 k0 = &anim.keyframes[i];
221 k1 = &anim.keyframes[i + 1];
226 float span = k1->t - k0->t;
227 float u = (span > 0.0f) ? (localT - k0->t) / span : 0.0f;
228 u =
getRatio(std::clamp(u, 0.0f, 1.0f), ease);
230#define X(T, name, def) \
231 if (k0->delta.name.is_set && k1->delta.name.is_set) \
232 out.name = lerpProp(k0->delta.name.value, k1->delta.name.value, u); \
233 else if (k0->delta.name.is_set) \
234 out.name = k0->delta.name.value; \
235 else if (k1->delta.name.is_set) \
236 out.name = k1->delta.name.value;
237 BUBBLE_STYLE_PROPS(X)
Centralized standard library includes used throughout ZenitUI.
Small value types shared by the layout, rendering and input layers.
The Style / ComputedStyle pair and all style-related value types.
The base node type: tree, style, layout, input, scroll, render.
Definition Layout.hpp:154
A time-parameterised sequence of per-property tracks.
Definition AnimPrimitives.hpp:51
void addTrack(T start, T end, Callable setter, TransitionFunction tr=TransitionFunction::Linear)
Append a typed track.
Definition AnimPrimitives.hpp:84
float sampleActive(const ActiveCssAnimation &a, bool &finished)
Sample the given CSS animation's local time without touching the cache.
Definition AnimPrimitives.hpp:150
Style evaluateKeyframes(const KeyframeAnimation &anim, float localT, TransitionFunction ease)
Interpolate a KeyframeAnimation at local time localT.
Definition AnimPrimitives.hpp:206
float sampleActiveCached(const ActiveCssAnimation &a, bool &finished)
Cached wrapper around sampleActive.
Definition AnimPrimitives.hpp:184
TransitionFunction
Timing function applied between two keyframe values.
Definition Easing.hpp:28
float getRatio(float t, TransitionFunction fn)
Map a normalized time t in [0, 1] through the given easing.
Definition Easing.hpp:49
Playback state for one CSS animation on one node.
Definition AnimPrimitives.hpp:122
Playback state for one UIAnimation on one node.
Definition AnimPrimitives.hpp:98
A named list of keyframes, keyed by name in Theme::keyframes.
Definition AnimPrimitives.hpp:115
One keyframe of a CSS animation: a normalized time and a sparse style delta.
Definition AnimPrimitives.hpp:108
Sparse style: every property is Opt<T>, unset by default.
Definition Style.hpp:932
Type-erased track interface.
Definition AnimPrimitives.hpp:55
virtual void apply(float raw_t, Layout *target)=0
Advance the track to normalized time raw_t.
Concrete typed track: start/end pair plus a setter.
Definition AnimPrimitives.hpp:64
void apply(float raw_t, Layout *target) override
Advance the track to normalized time raw_t.
Definition AnimPrimitives.hpp:72