pub fn lerp_i32(from: i32, to: i32, progress_permille: u16) -> i32Expand description
Linearly interpolates between two i32 values using permille progress.
Examples found in repository?
More examples
src/modal.rs (line 111)
100 pub fn current_with_panel(&self, bounds: Rectangle, panel: Rectangle) -> Option<ModalLayer<M>> {
101 let offscreen = offscreen_offset(bounds, panel);
102
103 match self.state {
104 ModalState::Hidden => None,
105 ModalState::Visible { modal } => Some(ModalLayer::new(modal, panel, 0, DIM_ALPHA_MAX)),
106 ModalState::Showing { modal, animation } => {
107 let progress = animation.progress_permille();
108 Some(ModalLayer::new(
109 modal,
110 panel,
111 lerp_i32(offscreen, 0, progress),
112 lerp_u8(0, DIM_ALPHA_MAX, progress),
113 ))
114 }
115 ModalState::Hiding { modal, animation } => {
116 let progress = animation.progress_permille();
117 Some(ModalLayer::new(
118 modal,
119 panel,
120 lerp_i32(0, offscreen, progress),
121 lerp_u8(DIM_ALPHA_MAX, 0, progress),
122 ))
123 }
124 }
125 }src/stack.rs (line 188)
172 pub fn layers(&self, frame: Rectangle) -> StackLayers<K> {
173 let width = frame.size.width as i32;
174 let idle = Layer::new(self.top(), frame, Point::zero());
175
176 match self.transition {
177 None => StackLayers {
178 base: idle,
179 overlay: None,
180 },
181 Some(Transition::Push {
182 from,
183 to,
184 animation,
185 }) => {
186 let progress = animation.progress_permille();
187 let base = Layer::new(from, frame, Point::zero());
188 let overlay = Layer::new(to, frame, Point::new(lerp_i32(width, 0, progress), 0));
189 StackLayers {
190 base,
191 overlay: Some(overlay),
192 }
193 }
194 Some(Transition::Pop {
195 from,
196 to,
197 animation,
198 }) => {
199 let progress = animation.progress_permille();
200 let base = Layer::new(to, frame, Point::zero());
201 let overlay = Layer::new(from, frame, Point::new(lerp_i32(0, width, progress), 0));
202 StackLayers {
203 base,
204 overlay: Some(overlay),
205 }
206 }
207 }
208 }src/stack_header.rs (line 47)
26pub(super) fn header_titles<'a, K: Copy, F, const N: usize>(
27 nav: &StackNav<K, N>,
28 header: Rectangle,
29 title_for: &F,
30 back_button: Option<&Button<'a, NavHeaderAction>>,
31) -> (
32 Option<Localized<'a>>,
33 HeaderTitle<'a>,
34 Option<HeaderTitle<'a>>,
35)
36where
37 F: Fn(K) -> Localized<'a>,
38{
39 let center = header.center();
40 let right = Point::new(center.x + header.size.width as i32, center.y);
41 let back = back_title_center(back_button);
42 match nav.header_transition() {
43 Some(HeaderTransition::Push { from, to, progress }) => (
44 None,
45 HeaderTitle {
46 title: title_for(from),
47 center: Point::new(lerp_i32(center.x, back.x, progress), center.y),
48 },
49 Some(HeaderTitle {
50 title: title_for(to),
51 center: Point::new(lerp_i32(right.x, center.x, progress), center.y),
52 }),
53 ),
54 Some(HeaderTransition::Pop { from, to, progress }) => (
55 None,
56 HeaderTitle {
57 title: title_for(to),
58 center: Point::new(lerp_i32(back.x, center.x, progress), center.y),
59 },
60 Some(HeaderTitle {
61 title: title_for(from),
62 center: Point::new(lerp_i32(center.x, right.x, progress), center.y),
63 }),
64 ),
65 None => (
66 nav.previous().map(title_for),
67 HeaderTitle {
68 title: title_for(nav.top()),
69 center,
70 },
71 None,
72 ),
73 }
74}