1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use embedded_graphics::{prelude::Point, primitives::Rectangle};
/// One render layer used by stack-style presentation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Layer<K> {
/// Stable layer key.
pub key: K,
/// Base frame for the layer.
pub frame: Rectangle,
/// Translation offset applied during animation.
pub offset: Point,
}
impl<K> Layer<K> {
/// Creates a layer.
pub const fn new(key: K, frame: Rectangle, offset: Point) -> Self {
Self { key, frame, offset }
}
/// Returns the translated frame after applying the current offset.
pub fn translated_frame(&self) -> Rectangle {
Rectangle::new(self.frame.top_left + self.offset, self.frame.size)
}
}
/// Render layer for a modal presentation.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ModalLayer<M> {
/// Modal identifier.
pub modal: M,
/// Settled panel frame.
pub panel: Rectangle,
/// Vertical offset applied during animation.
pub y_offset: i32,
/// Backdrop dimming alpha.
pub dim_alpha: u8,
}
impl<M> ModalLayer<M> {
/// Creates a modal layer.
pub const fn new(modal: M, panel: Rectangle, y_offset: i32, dim_alpha: u8) -> Self {
Self {
modal,
panel,
y_offset,
dim_alpha,
}
}
/// Returns the translated panel frame after applying `y_offset`.
pub fn translated_panel(&self) -> Rectangle {
Rectangle::new(
self.panel.top_left + Point::new(0, self.y_offset),
self.panel.size,
)
}
}