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
25impl CubicBezier {
26 pub const LINEAR: Self = Self {
28 x1: 0.0,
29 y1: 0.0,
30 x2: 1.0,
31 y2: 1.0,
32 };
33
34 pub const EASE: Self = Self {
36 x1: 0.25,
37 y1: 0.1,
38 x2: 0.25,
39 y2: 1.0,
40 };
41
42 pub const EASE_IN: Self = Self {
44 x1: 0.42,
45 y1: 0.0,
46 x2: 1.0,
47 y2: 1.0,
48 };
49
50 pub const EASE_OUT: Self = Self {
52 x1: 0.0,
53 y1: 0.0,
54 x2: 0.58,
55 y2: 1.0,
56 };
57
58 pub const EASE_IN_OUT: Self = Self {
60 x1: 0.42,
61 y1: 0.0,
62 x2: 0.58,
63 y2: 1.0,
64 };
65}
66
67#[derive(Clone, Copy, Debug, PartialEq)]
69pub enum MotionSpec {
70 Instant,
72 Spring(Spring),
74 Tween {
76 duration_ms: u16,
78 easing: CubicBezier,
80 },
81}
82
83#[derive(Clone, Copy, Debug, PartialEq, Eq)]
86pub enum MotionKind {
87 Spatial,
89 Effects,
91}
92
93#[derive(Clone, Copy, Debug, PartialEq, Eq)]
95pub enum MotionSpeed {
96 Fast,
98 Default,
100 Slow,
102}
103
104#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
106#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
107pub enum MotionScheme {
108 #[default]
110 Standard,
111 Expressive,
113}
114
115impl MotionScheme {
116 pub const fn spec(
119 self,
120 kind: MotionKind,
121 speed: MotionSpeed,
122 reduced_motion: bool,
123 ) -> MotionSpec {
124 use MotionKind::{Effects, Spatial};
125 use MotionSpeed::{Default, Fast, Slow};
126
127 if reduced_motion {
128 return MotionSpec::Instant;
129 }
130
131 let spring = match (self, kind, speed) {
132 (Self::Standard, Spatial, Fast) => MD_SYS_MOTION_STANDARD_SPRING_FAST_SPATIAL,
133 (Self::Standard, Spatial, Default) => MD_SYS_MOTION_STANDARD_SPRING_DEFAULT_SPATIAL,
134 (Self::Standard, Spatial, Slow) => MD_SYS_MOTION_STANDARD_SPRING_SLOW_SPATIAL,
135 (Self::Expressive, Spatial, Fast) => MD_SYS_MOTION_EXPRESSIVE_SPRING_FAST_SPATIAL,
136 (Self::Expressive, Spatial, Default) => MD_SYS_MOTION_EXPRESSIVE_SPRING_DEFAULT_SPATIAL,
137 (Self::Expressive, Spatial, Slow) => MD_SYS_MOTION_EXPRESSIVE_SPRING_SLOW_SPATIAL,
138 (Self::Standard, Effects, Fast) => MD_SYS_MOTION_STANDARD_SPRING_FAST_EFFECTS,
139 (Self::Standard, Effects, Default) => MD_SYS_MOTION_STANDARD_SPRING_DEFAULT_EFFECTS,
140 (Self::Standard, Effects, Slow) => MD_SYS_MOTION_STANDARD_SPRING_SLOW_EFFECTS,
141 (Self::Expressive, Effects, Fast) => MD_SYS_MOTION_EXPRESSIVE_SPRING_FAST_EFFECTS,
142 (Self::Expressive, Effects, Default) => MD_SYS_MOTION_EXPRESSIVE_SPRING_DEFAULT_EFFECTS,
143 (Self::Expressive, Effects, Slow) => MD_SYS_MOTION_EXPRESSIVE_SPRING_SLOW_EFFECTS,
144 };
145 MotionSpec::Spring(spring)
146 }
147}