mod duration;
mod error;
mod hold;
mod marker;
mod parallel;
mod sequence;
mod step;
#[cfg(test)]
mod tests;
mod track;
pub use error::TimelinePlaybackError;
pub use hold::Hold;
pub use marker::TimelineMarker;
pub use parallel::Parallel;
pub use sequence::Sequence;
pub use step::TimelineStep;
pub use track::{PropertyTrackBuilder, Track};
use crate::{keyframes::Keyframes, property::PropertySnapshot, timing::Duration};
#[derive(Debug, Clone, PartialEq, Default)]
pub struct Timeline {
name: Option<String>,
root: Sequence,
}
impl Timeline {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn with_name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
#[must_use]
pub fn sequence(steps: impl IntoIterator<Item = TimelineStep>) -> Self {
Self {
root: Sequence::from_steps(steps),
..Self::new()
}
}
#[must_use]
pub fn parallel(steps: impl IntoIterator<Item = TimelineStep>) -> Self {
Self::new().then(Parallel::from_steps(steps))
}
#[must_use]
pub fn track(track: impl Into<Track>) -> Self {
Self::new().then(track.into())
}
#[must_use]
pub fn keyframes(keyframes: Keyframes) -> Self {
Self::track(keyframes)
}
#[must_use]
pub fn hold(duration: impl Into<Duration>) -> Self {
Self::new().then(Hold::new(duration.into()))
}
#[must_use]
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}
#[must_use]
pub const fn root(&self) -> &Sequence {
&self.root
}
pub fn push_step(&mut self, step: impl Into<TimelineStep>) {
self.root.push_step(step);
}
#[must_use]
pub fn then(mut self, step: impl Into<TimelineStep>) -> Self {
self.push_step(step);
self
}
#[must_use]
pub fn total_duration(&self) -> Option<Duration> {
self.root.total_duration()
}
#[must_use]
pub fn sample_at(&self, offset: impl Into<Duration>) -> Option<PropertySnapshot> {
self.root.sample_at(offset.into())
}
#[must_use]
pub fn completion_snapshot(&self) -> Option<PropertySnapshot> {
self.root.completion_snapshot()
}
}