use num_traits::Float;
use easer::functions::Easing;
use crate::{fun, Anim, Fun};
impl<V, F> Anim<F>
where
V: Float,
F: Fun<T = V, V = V>,
{
fn seq_ease<G, H, A>(
self,
self_end: V,
ease: impl Fn(V, V, V) -> Anim<G>,
ease_duration: V,
next: A,
) -> Anim<impl Fun<T = V, V = V>>
where
G: Fun<T = V, V = V>,
H: Fun<T = V, V = V>,
A: Into<Anim<H>>,
{
let next = next.into();
let ease_start_value = self.eval(self_end);
let ease_end_value = next.eval(V::zero());
let ease_delta = ease_end_value - ease_start_value;
let ease = ease(ease_start_value, ease_delta, ease_duration);
self.seq(self_end, ease).seq(self_end + ease_duration, next)
}
pub fn seq_ease_in<E, G, A>(
self,
self_end: V,
_easing: E,
ease_duration: V,
next: A,
) -> Anim<impl Fun<T = V, V = V>>
where
E: Easing<V>,
G: Fun<T = V, V = V>,
A: Into<Anim<G>>,
{
self.seq_ease(self_end, ease_in::<E, V>, ease_duration, next)
}
pub fn seq_ease_out<E, G, A>(
self,
self_end: V,
_: E,
ease_duration: V,
next: A,
) -> Anim<impl Fun<T = V, V = V>>
where
E: Easing<V>,
G: Fun<T = V, V = V>,
A: Into<Anim<G>>,
{
self.seq_ease(self_end, ease_out::<E, V>, ease_duration, next)
}
pub fn seq_ease_in_out<E, G, A>(
self,
self_end: V,
_: E,
ease_duration: V,
next: A,
) -> Anim<impl Fun<T = V, V = V>>
where
E: Easing<V>,
G: Fun<T = V, V = V>,
A: Into<Anim<G>>,
{
self.seq_ease(self_end, ease_in_out::<E, V>, ease_duration, next)
}
}
pub fn ease_in<E, V>(start: V, delta: V, duration: V) -> Anim<impl Fun<T = V, V = V>>
where
V: Float,
E: Easing<V>,
{
fun(move |t| E::ease_in(t, start, delta, duration))
}
pub fn ease_out<E, V>(start: V, delta: V, duration: V) -> Anim<impl Fun<T = V, V = V>>
where
V: Float,
E: Easing<V>,
{
fun(move |t| E::ease_out(t, start, delta, duration))
}
pub fn ease_in_out<E, V>(start: V, delta: V, duration: V) -> Anim<impl Fun<T = V, V = V>>
where
V: Float,
E: Easing<V>,
{
fun(move |t| E::ease_in_out(t, start, delta, duration))
}