2024-09-17 13:19:24 +02:00
|
|
|
use crate::Button;
|
|
|
|
|
|
|
|
use super::*;
|
2024-09-18 13:23:15 +02:00
|
|
|
use profont::PROFONT_18_POINT;
|
2024-09-17 13:19:24 +02:00
|
|
|
use strum::IntoEnumIterator;
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, strum::EnumIter)]
|
|
|
|
enum MenuEntry {
|
|
|
|
#[default]
|
|
|
|
Labirynth,
|
|
|
|
Pairs,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MenuEntry {
|
|
|
|
fn as_str(&self) -> &str {
|
|
|
|
match self {
|
|
|
|
MenuEntry::Labirynth => "Labirynt",
|
|
|
|
MenuEntry::Pairs => "Pary",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn position(&self) -> Point {
|
|
|
|
match self {
|
2024-09-18 13:23:15 +02:00
|
|
|
MenuEntry::Labirynth => Point::new(20, 38),
|
|
|
|
MenuEntry::Pairs => Point::new(20, 68),
|
2024-09-17 13:19:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Menu {
|
|
|
|
selected: MenuEntry,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Menu {
|
|
|
|
pub fn new() -> Menu {
|
|
|
|
Menu {
|
|
|
|
selected: MenuEntry::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl App for Menu {
|
|
|
|
fn start(&mut self, _trng: &mut Trng) {}
|
|
|
|
|
|
|
|
fn update(&mut self, ctx: &Context) -> Action {
|
|
|
|
let Some(button) = ctx.button_pressed else {
|
|
|
|
return Action::Noop;
|
|
|
|
};
|
|
|
|
match button {
|
|
|
|
Button::Up => match self.selected {
|
|
|
|
MenuEntry::Labirynth => return Action::Noop,
|
|
|
|
MenuEntry::Pairs => {
|
|
|
|
self.selected = MenuEntry::Labirynth;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Button::Down => match self.selected {
|
|
|
|
MenuEntry::Labirynth => {
|
|
|
|
self.selected = MenuEntry::Pairs;
|
|
|
|
}
|
|
|
|
MenuEntry::Pairs => return Action::Noop,
|
|
|
|
},
|
|
|
|
Button::Circle => match self.selected {
|
|
|
|
MenuEntry::Labirynth => return Action::StartMaze,
|
|
|
|
MenuEntry::Pairs => return Action::StartPairs,
|
|
|
|
},
|
|
|
|
_ => return Action::Noop,
|
|
|
|
};
|
|
|
|
Action::Noop
|
|
|
|
}
|
|
|
|
|
|
|
|
fn draw(&self, display: &mut Display290TriColor) {
|
2024-09-18 13:23:15 +02:00
|
|
|
let style = MonoTextStyle::new(&PROFONT_18_POINT, TriColor::Black);
|
|
|
|
let selected_style = MonoTextStyle::new(&PROFONT_18_POINT, TriColor::Red);
|
2024-09-17 13:19:24 +02:00
|
|
|
|
|
|
|
MenuEntry::iter().for_each(|entry| {
|
2024-09-18 13:23:15 +02:00
|
|
|
if entry == self.selected {
|
|
|
|
let _ = Text::with_text_style(
|
|
|
|
"> ",
|
|
|
|
Point::new(2, entry.position().y),
|
|
|
|
selected_style,
|
|
|
|
TextStyle::default(),
|
|
|
|
)
|
|
|
|
.draw(display)
|
|
|
|
.unwrap();
|
|
|
|
};
|
|
|
|
|
2024-09-17 13:19:24 +02:00
|
|
|
let _ = Text::with_text_style(
|
|
|
|
entry.as_str(),
|
|
|
|
entry.position(),
|
|
|
|
if entry == self.selected {
|
|
|
|
selected_style
|
|
|
|
} else {
|
|
|
|
style
|
|
|
|
},
|
|
|
|
TextStyle::default(),
|
|
|
|
)
|
|
|
|
.draw(display)
|
|
|
|
.unwrap();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|