7#include "algorithm.hpp"
8#include "../macros.hpp"
9#include "../utility/utility.hpp"
10#include "../time/module.hpp"
34 bool update(value_type new_value, utc_nanoseconds current_time)
noexcept
36 if (not initialized) {
38 _old_value = new_value;
39 _new_value = new_value;
40 _start_time = current_time;
42 }
else if (new_value != _new_value) {
43 _old_value = _new_value;
44 _new_value = new_value;
45 _start_time = current_time;
47 _current_time = current_time;
48 return is_animating();
55 hi_axiom(initialized);
56 return progress() < 1.0f;
63 hi_axiom(initialized);
64 return std::lerp(_old_value, _new_value, progress());
68 value_type _old_value;
69 value_type _new_value;
70 utc_nanoseconds _start_time;
71 utc_nanoseconds _current_time;
73 bool initialized =
false;
75 float progress() const noexcept
77 using namespace std::chrono_literals;
79 hilet dt = _current_time - _start_time;
80 hilet p =
static_cast<float>(dt / 1ms) /
static_cast<float>(_animation_duration / 1ms);
81 return std::clamp(p, 0.0f, 1.0f);
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
A type that gets animated between two values.
Definition animator.hpp:20
animator(std::chrono::nanoseconds animation_duration) noexcept
Constructor.
Definition animator.hpp:27
bool update(value_type new_value, utc_nanoseconds current_time) noexcept
Update the value and time.
Definition animator.hpp:34
value_type current_value() const noexcept
The interpolated value between start and end value.
Definition animator.hpp:61
bool is_animating() const noexcept
Check if the animation is currently running.
Definition animator.hpp:53