use super::types::*;
use crate::animation::easing::Easing;
use std::time::Duration;
pub fn progress_bar_horizontal() -> ScrollAnimation {
ScrollAnimation::ProgressBar {
scroll_start: 0.0,
scroll_end: 10000.0, easing: Easing::Linear,
orientation: ProgressBarOrientation::Horizontal,
}
}
pub fn progress_ring() -> ScrollAnimation {
ScrollAnimation::ProgressBar {
scroll_start: 0.0,
scroll_end: 10000.0,
easing: Easing::Linear,
orientation: ProgressBarOrientation::Circular,
}
}
pub fn parallax_hero() -> ScrollAnimation {
ScrollAnimation::ParallaxLayers {
layer_speeds: vec![0.3, 0.6, 1.0],
axis: ParallaxAxis::Vertical,
}
}
pub fn fade_in_on_enter() -> ScrollAnimation {
ScrollAnimation::FadeOnScroll {
opacity_from: 0.0,
opacity_to: 1.0,
scroll_range: (0.0, 0.3), easing: Easing::EaseOutCubic,
}
}
pub fn slide_up_on_enter() -> ScrollAnimation {
ScrollAnimation::RevealOnEnter {
translate_y: 50.0,
opacity_from: 0.0,
entry_range: (0.0, 0.4),
duration: Duration::from_millis(600),
easing: Easing::EaseOutCubic,
}
}
pub fn reveal_from_left() -> ScrollAnimation {
ScrollAnimation::RevealOnEnter {
translate_y: 0.0, opacity_from: 1.0, entry_range: (0.0, 0.3),
duration: Duration::from_millis(500),
easing: Easing::EaseOutQuart,
}
}
pub fn sticky_shrink_header() -> ScrollAnimation {
ScrollAnimation::StickyHeader {
from_state: HeaderState {
scale: 1.0,
height: 80.0,
opacity: 1.0,
},
to_state: HeaderState {
scale: 0.9,
height: 48.0,
opacity: 0.95,
},
scroll_threshold: 100.0,
duration: Duration::from_millis(300),
easing: Easing::EaseInOutQuad,
}
}
pub fn horizontal_pin_scroll() -> ScrollAnimation {
ScrollAnimation::HorizontalScroll {
scroll_distance: 2000.0, vertical_range: (0.0, 3000.0), pin: true,
easing: Easing::Linear,
}
}
pub fn number_counter() -> ScrollAnimation {
ScrollAnimation::NumberCounter {
from: 0.0,
to: 100.0, threshold: 0.8, duration: Duration::from_millis(2000),
easing: Easing::EaseOutCubic, }
}
pub fn color_shift_sections() -> ScrollAnimation {
ScrollAnimation::ColorShift {
color_stops: vec![
(0.0, (0.4, 0.47, 0.92)), (0.33, (0.56, 0.27, 0.68)), (0.66, (0.96, 0.34, 0.42)), (1.0, (1.0, 0.6, 0.2)), ],
scroll_range: (0.0, 5000.0),
easing: Easing::EaseInOutSine,
}
}
pub fn scale_on_scroll() -> ScrollAnimation {
ScrollAnimation::FadeOnScroll {
opacity_from: 1.0, opacity_to: 1.0,
scroll_range: (0.0, 1.0), easing: Easing::EaseOutQuad,
}
}
pub fn parallax_text() -> ScrollAnimation {
ScrollAnimation::ParallaxLayers {
layer_speeds: vec![0.3, 0.7], axis: ParallaxAxis::Vertical,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_progress_bar_horizontal() {
let preset = progress_bar_horizontal();
match preset {
ScrollAnimation::ProgressBar { orientation, .. } => {
assert_eq!(orientation, ProgressBarOrientation::Horizontal);
}
_ => panic!("Expected ProgressBar variant"),
}
}
#[test]
fn test_parallax_hero_layers() {
let preset = parallax_hero();
match preset {
ScrollAnimation::ParallaxLayers { layer_speeds, .. } => {
assert_eq!(layer_speeds.len(), 3);
assert_eq!(layer_speeds[0], 0.3);
assert_eq!(layer_speeds[2], 1.0);
}
_ => panic!("Expected ParallaxLayers variant"),
}
}
#[test]
fn test_sticky_header_states() {
let preset = sticky_shrink_header();
match preset {
ScrollAnimation::StickyHeader {
from_state,
to_state,
..
} => {
assert_eq!(from_state.height, 80.0);
assert_eq!(to_state.height, 48.0);
}
_ => panic!("Expected StickyHeader variant"),
}
}
#[test]
fn test_number_counter_timing() {
let preset = number_counter();
match preset {
ScrollAnimation::NumberCounter {
duration, easing, ..
} => {
assert_eq!(duration, Duration::from_millis(2000));
assert_eq!(easing, Easing::EaseOutCubic);
}
_ => panic!("Expected NumberCounter variant"),
}
}
#[test]
fn test_color_shift_stops() {
let preset = color_shift_sections();
match preset {
ScrollAnimation::ColorShift { color_stops, .. } => {
assert_eq!(color_stops.len(), 4);
assert_eq!(color_stops[0].0, 0.0);
assert_eq!(color_stops[3].0, 1.0);
}
_ => panic!("Expected ColorShift variant"),
}
}
}