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
Definition animation.hpp:90
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
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
ftxui::Make
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26