FTXUI 6.1.9 C++ functional terminal UI.

Loading...
Searching...
No Matches
animation.hpp
Go to the documentation of this file.
1// Copyright 2022 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_ANIMATION_HPP
5#define FTXUI_ANIMATION_HPP
6
7#include <chrono> // for milliseconds, duration, steady_clock, time_point
8#include <functional> // for function
9
10 namespace ftxui::animation {
11/// @brief RequestAnimationFrame is a function that requests a new frame to be
12/// drawn in the next animation cycle.
13///
14/// @note This function is typically called by components that need to
15/// update their state or appearance over time, such as animations or
16/// transitions. This is useful when the change doesn't depend depend on the
17/// events seen by the terminal, but rather on the passage of time.
18///
19/// Components who haven't completed their animation can call this function to
20/// request a new frame to be drawn later.
21///
22/// When there is no new events and no animations to complete, no new frame is
23/// drawn.
24///
25/// @ingroup component
26 void RequestAnimationFrame();
27
28 using Clock = std::chrono::steady_clock;
29 using TimePoint = std::chrono::time_point<Clock>;
30 using Duration = std::chrono::duration<float>;
31
32// Parameter of Component::OnAnimation(param).
33 class Params {
34 public:
35 explicit Params(Duration duration) : duration_(duration) {}
36
37 /// The duration this animation step represents.
38 Duration duration() const { return duration_; }
39
40 private:
41 Duration duration_;
42};
43
44 namespace easing {
45 using Function = std::function<float(float)>;
46// Linear interpolation (no easing)
47 float Linear(float p);
48
49// Quadratic easing; p^2
50 float QuadraticIn(float p);
51 float QuadraticOut(float p);
52 float QuadraticInOut(float p);
53
54// Cubic easing; p^3
55 float CubicIn(float p);
56 float CubicOut(float p);
57 float CubicInOut(float p);
58
59// Quartic easing; p^4
60 float QuarticIn(float p);
61 float QuarticOut(float p);
62 float QuarticInOut(float p);
63
64// Quintic easing; p^5
65 float QuinticIn(float p);
66 float QuinticOut(float p);
67 float QuinticInOut(float p);
68
69// Sine wave easing; sin(p * PI/2)
70 float SineIn(float p);
71 float SineOut(float p);
72 float SineInOut(float p);
73
74// Circular easing; sqrt(1 - p^2)
75 float CircularIn(float p);
76 float CircularOut(float p);
77 float CircularInOut(float p);
78
79// Exponential easing, base 2
80 float ExponentialIn(float p);
81 float ExponentialOut(float p);
82 float ExponentialInOut(float p);
83
84// Exponentially-damped sine wave easing
85 float ElasticIn(float p);
86 float ElasticOut(float p);
87 float ElasticInOut(float p);
88
89// Overshooting cubic easing;
90 float BackIn(float p);
91 float BackOut(float p);
92 float BackInOut(float p);
93
94// Exponentially-decaying bounce easing
95 float BounceIn(float p);
96 float BounceOut(float p);
97 float BounceInOut(float p);
98} // namespace easing
99
100 class Animator {
101 public:
102 explicit Animator(float* from,
103 float to = 0.f,
104 Duration duration = std::chrono::milliseconds(250),
105 easing::Function easing_function = easing::Linear,
106 Duration delay = std::chrono::milliseconds(0));
107
108 void OnAnimation(Params&);
109
110 float to() const { return to_; }
111
112 private:
113 float* value_;
114 float from_;
115 float to_;
116 Duration duration_;
117 easing::Function easing_function_;
118 Duration current_;
119};
120
121} // namespace ftxui::animation
122
123#endif /* end of include guard: FTXUI_ANIMATION_HPP */
ftxui::animation::Animator
Definition animation.hpp:100
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:110
ftxui::animation::Animator::OnAnimation
void OnAnimation(Params &)
Definition animation.cpp:267
ftxui::animation::Params
Definition animation.hpp:33
ftxui::animation::Params::Params
Params(Duration duration)
Definition animation.hpp:35
ftxui::animation::Params::duration
Duration duration() const
The duration this animation step represents.
Definition animation.hpp:38
ftxui::animation::RequestAnimationFrame
void RequestAnimationFrame()
RequestAnimationFrame is a function that requests a new frame to be drawn in the next animation cycle...
Definition screen_interactive.cpp:63
easing
The FTXUI sf::animation::easing:: namespace.
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:45
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
The FTXUI ftxui::animation:: namespace.
Definition animation.hpp:10
ftxui::animation::Clock
std::chrono::steady_clock Clock
Definition animation.hpp:28
ftxui::animation::Duration
std::chrono::duration< float > Duration
Definition animation.hpp:30
ftxui::animation::TimePoint
std::chrono::time_point< Clock > TimePoint
Definition animation.hpp:29