1use crate::generated::*;
2
3#[derive(Clone, Copy, Debug, PartialEq)]
5pub struct Spring {
6 pub damping_ratio: f32,
8 pub stiffness: f32,
10}
11
12#[derive(Clone, Copy, Debug, PartialEq)]
14pub struct CubicBezier {
15 pub x1: f32,
17 pub y1: f32,
19 pub x2: f32,
21 pub y2: f32,
23}
24
25#[derive(Clone, Copy, Debug, PartialEq)]
27pub enum MotionSpec {
28 Instant,
30 Spring(Spring),
32 Tween {
34 duration_ms: u16,
36 easing: CubicBezier,
38 },
39}
40
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
44pub enum MotionKind {
45 Spatial,
47 Effects,
49}
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq)]
53pub enum MotionSpeed {
54 Fast,
56 Default,
58 Slow,
60}
61
62#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
64#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65pub enum MotionScheme {
66 #[default]
68 Standard,
69 Expressive,
71}
72
73impl MotionScheme {
74 pub const fn spec(
77 self,
78 kind: MotionKind,
79 speed: MotionSpeed,
80 reduced_motion: bool,
81 ) -> MotionSpec {
82 use MotionKind::{Effects, Spatial};
83 use MotionSpeed::{Default, Fast, Slow};
84
85 if reduced_motion {
86 return MotionSpec::Instant;
87 }
88
89 let spring = match (self, kind, speed) {
90 (Self::Standard, Spatial, Fast) => MD_SYS_MOTION_STANDARD_SPRING_FAST_SPATIAL,
91 (Self::Standard, Spatial, Default) => MD_SYS_MOTION_STANDARD_SPRING_DEFAULT_SPATIAL,
92 (Self::Standard, Spatial, Slow) => MD_SYS_MOTION_STANDARD_SPRING_SLOW_SPATIAL,
93 (Self::Expressive, Spatial, Fast) => MD_SYS_MOTION_EXPRESSIVE_SPRING_FAST_SPATIAL,
94 (Self::Expressive, Spatial, Default) => MD_SYS_MOTION_EXPRESSIVE_SPRING_DEFAULT_SPATIAL,
95 (Self::Expressive, Spatial, Slow) => MD_SYS_MOTION_EXPRESSIVE_SPRING_SLOW_SPATIAL,
96 (Self::Standard, Effects, Fast) => MD_SYS_MOTION_STANDARD_SPRING_FAST_EFFECTS,
97 (Self::Standard, Effects, Default) => MD_SYS_MOTION_STANDARD_SPRING_DEFAULT_EFFECTS,
98 (Self::Standard, Effects, Slow) => MD_SYS_MOTION_STANDARD_SPRING_SLOW_EFFECTS,
99 (Self::Expressive, Effects, Fast) => MD_SYS_MOTION_EXPRESSIVE_SPRING_FAST_EFFECTS,
100 (Self::Expressive, Effects, Default) => MD_SYS_MOTION_EXPRESSIVE_SPRING_DEFAULT_EFFECTS,
101 (Self::Expressive, Effects, Slow) => MD_SYS_MOTION_EXPRESSIVE_SPRING_SLOW_EFFECTS,
102 };
103 MotionSpec::Spring(spring)
104 }
105}