use orbital_motion::{MotionDuration, PresenceMotion};
#[derive(Clone, Debug)]
pub struct ChartMotion {
pub skip_animation: bool,
pub stagger: MotionDuration,
pub entrance: Option<PresenceMotion>,
}
impl Default for ChartMotion {
fn default() -> Self {
Self {
skip_animation: false,
stagger: MotionDuration::Normal,
entrance: None,
}
}
}
pub fn effective_skip_animation(
skip_animation: Option<bool>,
motion: Option<&ChartMotion>,
prefers_reduced_motion: bool,
) -> bool {
skip_animation.unwrap_or(false)
|| motion.map(|m| m.skip_animation).unwrap_or(false)
|| prefers_reduced_motion
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn effective_skip_animation_respects_all_sources() {
assert!(!effective_skip_animation(None, None, false));
assert!(effective_skip_animation(Some(true), None, false));
assert!(effective_skip_animation(
None,
Some(&ChartMotion {
skip_animation: true,
..Default::default()
}),
false
));
assert!(effective_skip_animation(None, None, true));
}
}