Ugly menus

Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-19 23:37:24 +02:00
parent dea348152d
commit 395f266000
2 changed files with 72 additions and 12 deletions

View file

@ -1,6 +1,6 @@
use crate::apps::BeoApp;
#[derive(Debug)]
#[derive(Debug, Clone, PartialEq)]
enum SpotifyMenuState {
Root,
Genres,
@ -13,6 +13,7 @@ enum SpotifyMenuState {
pub struct Spotify {
i: i32,
state: SpotifyMenuState,
breadcrumb_states: Vec<SpotifyMenuState>,
}
impl Spotify {
@ -20,6 +21,7 @@ impl Spotify {
Spotify {
i: 0,
state: SpotifyMenuState::Root,
breadcrumb_states: vec![],
}
}
}
@ -29,14 +31,42 @@ impl BeoApp for Spotify {
"Spotify"
}
fn enter_menu(&mut self, _menu_id: usize) {
fn enter_menu(&mut self, menu_id: usize) {
self.breadcrumb_states.push(self.state.clone());
match (&self.state, menu_id) {
(SpotifyMenuState::Root, 0) => {
self.state = SpotifyMenuState::Genres;
}
(SpotifyMenuState::Genres, i) => {
self.state = SpotifyMenuState::Genre(format!("{}", i));
}
(SpotifyMenuState::Root, 1) => {
self.state = SpotifyMenuState::Playlists;
}
(SpotifyMenuState::Playlists, i) => {
self.state = SpotifyMenuState::Playlist(format!("{}", i));
}
(SpotifyMenuState::Genre(i), 0) => {
self.state = SpotifyMenuState::Genres;
}
_ => {
println!("Invalid state transition");
}
}
println!("Spotify2 entered");
println!("Spotify2 state: {:?}", self.state);
self.i += 1;
}
fn exit_menu(&mut self) {
println!("Spotify2 exited");
println!("Previous states: {:?}", self.breadcrumb_states);
self.i -= 1;
if let Some(previous_state) = self.breadcrumb_states.pop() {
println!("Setting state to {:?}", previous_state);
self.state = previous_state;
}
}
fn go(&mut self, _menu_id: usize) {
@ -44,16 +74,39 @@ impl BeoApp for Spotify {
}
fn get_current_view(&self) -> crate::apps::AppView {
crate::apps::AppView {
title: "Spotify".to_string(),
menus: vec![
crate::apps::Title {
title: format!("Genre {}", self.i),
},
crate::apps::Title {
title: format!("Playlist {}", self.i),
},
],
match self.state {
SpotifyMenuState::Root => {
return crate::apps::AppView {
title: "Spotify".to_string(),
menus: vec![
crate::apps::Title {
title: "Genres".to_string(),
},
crate::apps::Title {
title: "Playlists".to_string(),
},
],
};
}
SpotifyMenuState::Genres => {
return crate::apps::AppView {
title: "Genres".to_string(),
menus: vec![
crate::apps::Title {
title: "RNB".to_string(),
},
crate::apps::Title {
title: "POP".to_string(),
},
],
};
}
_ => {
return crate::apps::AppView {
title: "Got lost somehow".to_string(),
menus: vec![],
};
}
}
}
}

View file

@ -86,6 +86,10 @@ impl BeoUi {
if let Some(selected_app) = self.current_app() {
let menu_count = selected_app.get_current_view().menus.len();
if menu_count == 0 {
// No menu
return;
}
let max_angle = (menu_count - 1) as f32 * ANGLE_DEG_BETWEEN_MENU_ITEMS + 10.;
if self.angle_shift > max_angle {
@ -100,6 +104,9 @@ impl BeoUi {
if let Some(selected_app) = self.current_app() {
let actual_menu = selected_app.get_current_view().menus;
let menu_count = actual_menu.len();
if menu_count == 0 {
return None;
}
let max_angle = (menu_count - 1) as f32 * ANGLE_DEG_BETWEEN_MENU_ITEMS - 10.;
let angle = angle.min(max_angle);