Loading...
Searching...
No Matches
animation.hpp
Go to the documentation of this file.
// Copyright 2022 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
#ifndef FTXUI_ANIMATION_HPP
#define FTXUI_ANIMATION_HPP
#include <chrono> // for milliseconds, duration, steady_clock, time_point
#include <functional> // for function
namespace ftxui::animation {
// Components who haven't completed their animation can call this function to
// request a new frame to be drawn later.
//
// When there is no new events and no animations to complete, no new frame is
// drawn.
void RequestAnimationFrame();
using Clock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<Clock>;
using Duration = std::chrono::duration<float>;
// Parameter of Component::OnAnimation(param).
class Params {
public:
explicit Params(Duration duration) : duration_(duration) {}
/// The duration this animation step represents.
Duration duration() const { return duration_; }
private:
Duration duration_;
};
namespace easing {
using Function = std::function<float(float)>;
// Linear interpolation (no easing)
float Linear(float p);
// Quadratic easing; p^2
float QuadraticIn(float p);
float QuadraticOut(float p);
float QuadraticInOut(float p);
// Cubic easing; p^3
float CubicIn(float p);
float CubicOut(float p);
float CubicInOut(float p);
// Quartic easing; p^4
float QuarticIn(float p);
float QuarticOut(float p);
float QuarticInOut(float p);
// Quintic easing; p^5
float QuinticIn(float p);
float QuinticOut(float p);
float QuinticInOut(float p);
// Sine wave easing; sin(p * PI/2)
float SineIn(float p);
float SineOut(float p);
float SineInOut(float p);
// Circular easing; sqrt(1 - p^2)
float CircularIn(float p);
float CircularOut(float p);
float CircularInOut(float p);
// Exponential easing, base 2
float ExponentialIn(float p);
float ExponentialOut(float p);
float ExponentialInOut(float p);
// Exponentially-damped sine wave easing
float ElasticIn(float p);
float ElasticOut(float p);
float ElasticInOut(float p);
// Overshooting cubic easing;
float BackIn(float p);
float BackOut(float p);
float BackInOut(float p);
// Exponentially-decaying bounce easing
float BounceIn(float p);
float BounceOut(float p);
float BounceInOut(float p);
} // namespace easing
class Animator {
public:
explicit Animator(float* from,
float to = 0.f,
Duration duration = std::chrono::milliseconds(250),
easing::Function easing_function = easing::Linear,
Duration delay = std::chrono::milliseconds(0));
void OnAnimation(Params&);
float to() const { return to_; }
private:
float* value_;
float from_;
float to_;
Duration duration_;
easing::Function easing_function_;
Duration current_;
};
} // namespace ftxui::animation
#endif /* end of include guard: FTXUI_ANIMATION_HPP */
ftxui::animation::Animator::Animator
Animator(float *from, float to=0.f, Duration duration=std::chrono::milliseconds(250), easing::Function easing_function=easing::Linear, Duration delay=std::chrono::milliseconds(0))
Definition animation.cpp:253
ftxui::animation::Animator::to
float to() const
Definition animation.hpp:100
ftxui::animation::Animator::OnAnimation
void OnAnimation(Params &)
Definition animation.cpp:267
ftxui::animation::Params
Definition animation.hpp:23
ftxui::animation::Params::Params
Params(Duration duration)
Definition animation.hpp:25
ftxui::animation::Params::duration
Duration duration() const
The duration this animation step represents.
Definition animation.hpp:28
ftxui::animation::easing
Definition animation.hpp:34
ftxui::animation::easing::ElasticIn
float ElasticIn(float p)
Definition animation.cpp:177
ftxui::animation::easing::CircularInOut
float CircularInOut(float p)
Definition animation.cpp:144
ftxui::animation::easing::SineInOut
float SineInOut(float p)
Definition animation.cpp:127
ftxui::animation::easing::BounceInOut
float BounceInOut(float p)
Definition animation.cpp:244
ftxui::animation::easing::CubicIn
float CubicIn(float p)
Definition animation.cpp:51
ftxui::animation::easing::CubicInOut
float CubicInOut(float p)
Definition animation.cpp:64
ftxui::animation::easing::Linear
float Linear(float p)
Modeled after the line y = x.
Definition animation.cpp:29
ftxui::animation::easing::BounceIn
float BounceIn(float p)
Definition animation.cpp:224
ftxui::animation::easing::CircularOut
float CircularOut(float p)
Definition animation.cpp:137
ftxui::animation::easing::BackOut
float BackOut(float p)
Definition animation.cpp:207
ftxui::animation::easing::BackInOut
float BackInOut(float p)
Definition animation.cpp:215
ftxui::animation::easing::ExponentialInOut
float ExponentialInOut(float p)
Definition animation.cpp:164
ftxui::animation::easing::ElasticInOut
float ElasticInOut(float p)
Definition animation.cpp:191
ftxui::animation::easing::QuarticInOut
float QuarticInOut(float p)
Definition animation.cpp:86
ftxui::animation::easing::QuadraticInOut
float QuadraticInOut(float p)
Definition animation.cpp:46
ftxui::animation::easing::QuarticOut
float QuarticOut(float p)
Definition animation.cpp:78
ftxui::animation::easing::SineOut
float SineOut(float p)
Definition animation.cpp:122
ftxui::animation::easing::CircularIn
float CircularIn(float p)
Definition animation.cpp:132
ftxui::animation::easing::ExponentialOut
float ExponentialOut(float p)
Definition animation.cpp:157
ftxui::animation::easing::QuadraticOut
float QuadraticOut(float p)
Definition animation.cpp:39
ftxui::animation::easing::QuinticOut
float QuinticOut(float p)
Definition animation.cpp:100
ftxui::animation::easing::QuadraticIn
float QuadraticIn(float p)
Modeled after the parabola y = x^2.
Definition animation.cpp:34
ftxui::animation::easing::ExponentialIn
float ExponentialIn(float p)
Definition animation.cpp:152
ftxui::animation::easing::QuinticIn
float QuinticIn(float p)
Definition animation.cpp:95
ftxui::animation::easing::BounceOut
float BounceOut(float p)
Definition animation.cpp:228
ftxui::animation::easing::CubicOut
float CubicOut(float p)
Definition animation.cpp:56
ftxui::animation::easing::ElasticOut
float ElasticOut(float p)
Definition animation.cpp:184
ftxui::animation::easing::Function
std::function< float(float)> Function
Definition animation.hpp:35
ftxui::animation::easing::BackIn
float BackIn(float p)
Definition animation.cpp:202
ftxui::animation::easing::SineIn
float SineIn(float p)
Definition animation.cpp:117
ftxui::animation::easing::QuarticIn
float QuarticIn(float p)
Definition animation.cpp:73
ftxui::animation::easing::QuinticInOut
float QuinticInOut(float p)
Definition animation.cpp:108
ftxui::animation
Definition animation.hpp:10
ftxui::animation::Clock
std::chrono::steady_clock Clock
Definition animation.hpp:18
ftxui::animation::Duration
std::chrono::duration< float > Duration
Definition animation.hpp:20
ftxui::animation::TimePoint
std::chrono::time_point< Clock > TimePoint
Definition animation.hpp:19
ftxui::animation::RequestAnimationFrame
void RequestAnimationFrame()
Definition screen_interactive.cpp:63