main menu: fix int overflow
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
parent
91172deddd
commit
40b0cd7a90
2 changed files with 19 additions and 2 deletions
17
src/apps.rs
17
src/apps.rs
|
@ -8,6 +8,23 @@ pub struct MainMenu {
|
|||
pub names: Vec<String>,
|
||||
}
|
||||
|
||||
impl MainMenu {
|
||||
pub fn selected_name(&self) -> &str {
|
||||
&self.names[self.selected_id]
|
||||
}
|
||||
|
||||
pub fn go_left(&mut self) {
|
||||
if self.selected_id > 0 {
|
||||
self.selected_id -= 1;
|
||||
}
|
||||
}
|
||||
pub fn go_right(&mut self) {
|
||||
if self.selected_id < self.names.len() - 1 {
|
||||
self.selected_id += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AppBase {
|
||||
name: String,
|
||||
pub main_menu: MainMenu,
|
||||
|
|
|
@ -44,13 +44,13 @@ impl BeoUi {
|
|||
Beo5Event::LeftButtonPressed => {
|
||||
println!("Left button pressed");
|
||||
if let Some(selected_app) = self.current_app_mut() {
|
||||
selected_app.base_mut().main_menu.selected_id += 1;
|
||||
selected_app.base_mut().main_menu.go_left();
|
||||
}
|
||||
}
|
||||
Beo5Event::RightButtonPressed => {
|
||||
println!("Right button pressed");
|
||||
if let Some(selected_app) = self.current_app_mut() {
|
||||
selected_app.base_mut().main_menu.selected_id -= 1;
|
||||
selected_app.base_mut().main_menu.go_right();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
|
|
Loading…
Reference in a new issue