-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphical layout
More file actions
48 lines (42 loc) · 1.21 KB
/
Copy pathGraphical layout
File metadata and controls
48 lines (42 loc) · 1.21 KB
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
// crates/sentinel-display/src/ui.rs
// Graphical layout and state management engine for the ESP32-S3 rotary display interface.
#![no_std]
pub enum DisplayScreen {
StatusOverview,
MeshPeers,
OpticalTransfer,
SystemSettings,
}
pub struct UIRenderEngine {
current_screen: DisplayScreen,
selected_index: usize,
max_options: usize,
}
impl UIRenderEngine {
pub const fn new() -> Self {
Self {
current_screen: DisplayScreen::StatusOverview,
selected_index: 0,
max_options: 4,
}
}
pub fn navigate(&mut self, direction: i8) {
if direction > 0 {
self.selected_index = (self.selected_index + 1) % self.max_options;
} else {
self.selected_index = if self.selected_index == 0 {
self.max_options - 1
} else {
self.selected_index - 1
};
}
}
pub fn select_active_screen(&mut self) {
self.current_screen = match self.selected_index {
0 => DisplayScreen::StatusOverview,
1 => DisplayScreen::MeshPeers,
2 => DisplayScreen::OpticalTransfer,
_ => DisplayScreen::SystemSettings,
};
}
}