eazy_keyframe/lib.rs
1//! eazy-keyframes — Keyframe-based animation system.
2//!
3//! Provides keyframe tracks for defining complex animations with
4//! values at specific time points and per-segment easing.
5//!
6//! # Examples
7//!
8//! ## Using the builder API
9//!
10//! ```rust
11//! use eazy_keyframes::{KeyframeTrack, Keyframe};
12//! use eazy_core::Easing;
13//!
14//! let track = KeyframeTrack::new()
15//! .keyframe(0.0, [0.0_f32, 0.0, 0.0])
16//! .keyframe_eased(0.5, [100.0, 50.0, 0.0], Easing::OutElastic)
17//! .keyframe(1.0, [0.0, 100.0, 0.0]);
18//!
19//! // Sample at 75% through the animation
20//! let position = track.sample(0.75);
21//! ```
22//!
23//! ## Using the keyframes! macro
24//!
25//! ```rust
26//! use eazy_keyframes::{keyframes, Easing};
27//!
28//! let track = keyframes![
29//! (0.0, 0.0_f32), // (time, value) - linear
30//! (0.5, 100.0, Easing::OutBounce), // (time, value, easing)
31//! (1.0, 50.0)
32//! ];
33//!
34//! let value = track.sample(0.75);
35//! ```
36
37pub mod keyframe;
38pub mod track;
39
40// Re-export main types.
41pub use keyframe::Keyframe;
42pub use keyframe::keyframe;
43pub use keyframe::keyframe_eased;
44pub use track::KeyframeTrack;
45
46// Re-export dependencies for convenience.
47pub use eazy_core::Easing;
48pub use eazy_tweener::Tweenable;
49
50/// Create a [`KeyframeTrack`] from a list of keyframe tuples.
51///
52/// Supports two tuple formats:
53/// - `(time, value)` — keyframe with linear easing
54/// - `(time, value, easing)` — keyframe with custom easing
55///
56/// # Examples
57///
58/// ```rust
59/// use eazy_keyframes::{keyframes, Easing};
60///
61/// // Simple f32 animation
62/// let track = keyframes![
63/// (0.0, 0.0_f32),
64/// (0.5, 100.0, Easing::OutBounce),
65/// (1.0, 50.0)
66/// ];
67///
68/// // Array animation (e.g., position)
69/// let track = keyframes![
70/// (0.0, [0.0_f32, 0.0]),
71/// (0.5, [100.0, 50.0], Easing::OutElastic),
72/// (1.0, [0.0, 100.0])
73/// ];
74/// ```
75#[macro_export]
76macro_rules! keyframes {
77 // Empty case.
78 () => {
79 $crate::KeyframeTrack::new()
80 };
81
82 // One or more keyframes.
83 ($($kf:expr),+ $(,)?) => {{
84 let keyframes: ::std::vec::Vec<$crate::Keyframe<_>> = ::std::vec![
85 $($kf.into()),+
86 ];
87
88 $crate::KeyframeTrack::from(keyframes)
89 }};
90}