Skip to main content

embedded_gui/
transition_preset.rs

1//! Named screen transition presets with default durations and easing.
2//!
3//! Durations assume a 30 Hz frame interval (`FRAME_INTERVAL_MS` = 33 ms).
4
5use crate::{
6    animation::Easing,
7    animation_timing::{
8        DEFAULT_DURATION_MS, MOOOK_DURATION_MS, PORT_HOLE_DURATION_MS, SHUTTER_DURATION_MS,
9    },
10    screen_transition::{ScreenTransitionEffect, ScreenTransitionSpec},
11};
12
13/// Built-in screen transition presets for common navigation patterns.
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15pub enum TransitionPreset {
16    /// Instant cut (no animation).
17    None,
18    /// Horizontal push onto the stack (spatial moook curve).
19    WindowPush,
20    /// Horizontal pop off the stack (spatial moook curve).
21    WindowPop,
22    /// Round-style push (two-phase port-hole slide).
23    WindowPushRound,
24    /// Round-style pop (two-phase port-hole slide).
25    WindowPopRound,
26    /// Directional shutter wipes.
27    ShutterUp,
28    ShutterDown,
29    ShutterLeft,
30    ShutterRight,
31    /// Card-style flip toward launcher.
32    RoundFlipToLauncher,
33    /// Card-style flip from launcher.
34    RoundFlipFromLauncher,
35    /// Two-phase port-hole slides.
36    PortHoleUp,
37    PortHoleDown,
38    PortHoleLeft,
39    PortHoleRight,
40    /// Modal presented from the bottom.
41    ModalPresent,
42    /// Modal dismissed toward the bottom.
43    ModalDismiss,
44    /// Timeline-style horizontal slide.
45    TimelineSlide,
46    /// Timeline peek card enters with a soft rightward reveal.
47    TimelinePeekIn,
48    /// Timeline peek card exits with a soft leftward collapse.
49    TimelinePeekOut,
50    /// Timeline pin details expand from lower edge.
51    TimelinePinExpand,
52    /// Timeline scrub release settles quickly.
53    TimelineScrubSettle,
54    /// Cross-fade.
55    Fade,
56}
57
58impl TransitionPreset {
59    pub const fn spec(self) -> ScreenTransitionSpec {
60        match self {
61            Self::None => ScreenTransitionSpec::none(),
62            Self::WindowPush => ScreenTransitionSpec::push_moook(MOOOK_DURATION_MS),
63            Self::WindowPop => ScreenTransitionSpec::pop_moook(MOOOK_DURATION_MS),
64            Self::WindowPushRound => ScreenTransitionSpec::port_hole_left(PORT_HOLE_DURATION_MS),
65            Self::WindowPopRound => ScreenTransitionSpec::port_hole_right(PORT_HOLE_DURATION_MS),
66            Self::ShutterUp => ScreenTransitionSpec::shutter_up(SHUTTER_DURATION_MS),
67            Self::ShutterDown => ScreenTransitionSpec::shutter_down(SHUTTER_DURATION_MS),
68            Self::ShutterLeft => ScreenTransitionSpec::shutter_left(SHUTTER_DURATION_MS),
69            Self::ShutterRight => ScreenTransitionSpec::shutter_right(SHUTTER_DURATION_MS),
70            Self::RoundFlipToLauncher => {
71                ScreenTransitionSpec::round_flip_right(PORT_HOLE_DURATION_MS)
72            }
73            Self::RoundFlipFromLauncher => {
74                ScreenTransitionSpec::round_flip_left(PORT_HOLE_DURATION_MS)
75            }
76            Self::PortHoleUp => ScreenTransitionSpec::port_hole_up(PORT_HOLE_DURATION_MS),
77            Self::PortHoleDown => ScreenTransitionSpec::port_hole_down(PORT_HOLE_DURATION_MS),
78            Self::PortHoleLeft => ScreenTransitionSpec::port_hole_left(PORT_HOLE_DURATION_MS),
79            Self::PortHoleRight => ScreenTransitionSpec::port_hole_right(PORT_HOLE_DURATION_MS),
80            Self::ModalPresent => ScreenTransitionSpec::modal_slide_up(DEFAULT_DURATION_MS),
81            Self::ModalDismiss => ScreenTransitionSpec::modal_slide_down(DEFAULT_DURATION_MS),
82            Self::TimelineSlide => {
83                ScreenTransitionSpec::slide_left(DEFAULT_DURATION_MS).with_easing(Easing::EaseInOut)
84            }
85            Self::TimelinePeekIn => ScreenTransitionSpec::slide_right(MOOOK_DURATION_MS / 2)
86                .with_easing(Easing::OutBack),
87            Self::TimelinePeekOut => {
88                ScreenTransitionSpec::slide_left(MOOOK_DURATION_MS / 2).with_easing(Easing::InSine)
89            }
90            Self::TimelinePinExpand => ScreenTransitionSpec::modal_slide_up(MOOOK_DURATION_MS / 2)
91                .with_easing(Easing::OutCubic),
92            Self::TimelineScrubSettle => ScreenTransitionSpec::slide_left(DEFAULT_DURATION_MS / 2)
93                .with_easing(Easing::OutBounce),
94            Self::Fade => ScreenTransitionSpec::fade(DEFAULT_DURATION_MS),
95        }
96    }
97
98    pub const fn effect(self) -> ScreenTransitionEffect {
99        self.spec().effect
100    }
101}
102
103impl From<TransitionPreset> for ScreenTransitionSpec {
104    fn from(value: TransitionPreset) -> Self {
105        value.spec()
106    }
107}