23#include "guillaume/components/animation.hpp"
25#include "guillaume/theme.hpp"
43 if (_duration == duration) {
58 if (_elapsed == elapsed) {
68 if (_duration <= 0.0f) {
69 return _playing ? 0.0f : 1.0f;
71 return std::clamp(_elapsed / _duration, 0.0f, 1.0f);
102 if (_looping == looping) {
117 if (_easing == easing) {
138 _onComplete = handler;
153 if (_duration <= 0.0f) {
167 _elapsed += std::max(0.0f, deltaTime);
170 if (_elapsed >= _duration) {
171 _elapsed = _duration;
188 _onSample(motion::applyEasing(_easing,
getProgress()));
float getProgress(void) const
Get how far the current run is, before easing.
void advance(float deltaTime)
Move the animation forward in time and call the handlers.
float getElapsed(void) const
Get the time spent in the current run.
bool isLooping(void) const
Check whether the animation starts again when it completes.
CompleteHandler getOnCompleteHandler(void) const
Get the callback run when the animation reaches its duration.
motion::Easing getEasing(void) const
Get the curve that turns the linear progress into the value passed to the sample handler.
Animation & setEasing(motion::Easing easing)
Set the curve that turns the linear progress into the value passed to the sample handler.
std::function< void(void)> CompleteHandler
Called on completion.
Animation & setDuration(float duration)
Set how long one run of the animation lasts.
Animation & setElapsed(float elapsed)
Move the animation to a point in time, without calling any handler.
SampleHandler getOnSampleHandler(void) const
Get the callback that applies the animation.
Animation(void)
Construct a stopped animation lasting the Material 3 Medium2 motion duration of the theme.
Animation & setOnSampleHandler(const SampleHandler &handler)
Store the callback that applies the animation.
Animation & play(void)
Start the animation from the beginning, even when it is already running.
float getDuration(void) const
Get how long one run of the animation lasts.
Animation & setLooping(bool looping)
Set whether the animation starts again when it completes.
Animation & setOnCompleteHandler(const CompleteHandler &handler)
Store the callback run when the animation reaches its duration.
Animation & stop(void)
Stop the animation and bring the elapsed time back to 0.
bool isPlaying(void) const
Check whether the animation is running.
std::function< void(float)> SampleHandler
Receives the eased progress.
void setHasChanged(bool hasChanged)
Raise or lower the changed flag.
State. Every class here is plain data attached to an entity.
Design tokens: colors, type scale, shapes, elevation, motion and spacing. Read them through guillaume...
float getMotionDuration(theme::MotionDuration duration)
Get the length the active theme gives to a duration token.