Compare commits

...

7 commits

Author SHA1 Message Date
2be1f544a3 handle volume chance
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-09-24 19:43:49 +02:00
e932ee0b0a make it betterer
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-09-22 21:14:19 +02:00
395f266000 Ugly menus
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-05-19 23:44:55 +02:00
dea348152d fix panic
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-05-19 22:47:19 +02:00
a1428eafdb oauua
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-05-19 22:45:41 +02:00
15f5d8dc3c change app working model
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-05-16 23:44:38 +02:00
511b4f22b5 change app working model
Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
2024-05-16 23:43:56 +02:00
9 changed files with 2382 additions and 376 deletions

2001
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -18,3 +18,6 @@ image = { version = "0.24.0", default-features = false, features = [
"png",
] }
nix = { version = "0.28.0", features = ["event", "fs"] }
librespot = "0.4.2"
mpd = "0.1.0"
pulsectl-rs = "0.3.2"

19
radios.txt Normal file
View file

@ -0,0 +1,19 @@
Couleur3∞http://stream.srg-ssr.ch/m/couleur3/aacp_96
Energy Basel (NRJ)∞https://energybasel.ice.infomaniak.ch/energybasel-high.mp3
Energy Bern∞https://energybern.ice.infomaniak.ch/energybern-high.mp3
Energy Bern (NRJ)∞http://broadcast.infomaniak.ch/energybern-high.mp3
Energy Blick Trendz∞http://energyzuerich.ice.infomaniak.ch/energyzuerich-high.mp3
Energy Luzern∞https://energyluzern.ice.infomaniak.ch/energyluzern-high.mp3
Energy St. Gallen (NRJ)∞https://energystgallen.ice.infomaniak.ch/energystgallen-high.mp3
Energy Zürich (NRJ)∞http://broadcast.infomaniak.ch/energyzuerich-high.mp3
NRJ Léman 103,6 FM∞http://cdn.nrjaudio.fm/audio1/ch/50001/mp3_128.mp3
One FM∞http://onefm.ice.infomaniak.ch/onefm-high.mp3
One FM 2000s∞https://webradio0009.ice.infomaniak.ch/webradio0009-128.mp3
One FM 90s∞https://webradio0006.ice.infomaniak.ch/webradio0006-128.mp3
One FM New-Hits∞https://webradio0001.ice.infomaniak.ch/webradio0001-128.mp3
Radio 1∞http://stream.radio1.ch/128k.m3u
Radio SRF 1∞http://stream.srg-ssr.ch/drs1/aacp_32.m3u
Radio SRF 2 Kultur∞http://stream.srg-ssr.ch/drs2/aacp_32.m3u
Radio SRF 4 News∞https://stream.srg-ssr.ch/m/drs4news/aacp_32
Radio Swiss Jazz∞http://stream.srg-ssr.ch/m/rsj/aacp_96
Radio Swiss Pop∞http://stream.srg-ssr.ch/m/rsp/aacp_96

View file

@ -1,219 +1,38 @@
mod radio;
use crate::spotify::Spotify;
use radio::Radio;
pub struct BeoApps {
pub apps: Vec<Box<dyn App>>,
pub apps: Vec<Box<dyn BeoApp>>,
}
pub struct AppBase {
name: String,
pub main_menu: Menu,
#[derive(Debug)]
pub struct Title {
pub title: String,
//pub image…
}
impl AppBase {
pub fn name(&self) -> &str {
&self.name
}
pub fn enter_submenu(&mut self, submenu_id: usize) {
let mut current_menu = &mut self.main_menu;
while let Some(ref mut selected_submenu) = current_menu.selected_submenu {
current_menu = selected_submenu
}
current_menu.set_submenu_id(submenu_id)
}
pub fn exit_submenu(&mut self) {
let current_menu = &mut self.main_menu;
while let Some(ref mut selected_submenu) = current_menu.selected_submenu {
if selected_submenu.selected_submenu.is_none() {
current_menu.selected_submenu = None;
return;
}
}
}
pub struct TitleEntry {
pub title: String,
pub id: usize,
}
#[derive(Debug, Clone)]
pub struct Menu {
pub submenus: Vec<Menu>,
current_submenu_id: usize,
pub selected_submenu: Option<Box<Menu>>,
pub name: String,
//pub image: Option<Image>,
#[derive(Debug)]
pub struct AppView {
pub title: String,
pub menus: Vec<Title>,
}
impl Menu {
pub fn set_submenu_id(&mut self, id: usize) {
if id >= self.submenus.len() {
panic!("Invalid submenu id");
}
self.current_submenu_id = id;
self.selected_submenu = Some(Box::new(self.submenus[self.current_submenu_id].clone()));
}
pub trait BeoApp {
fn name(&self) -> &str;
fn enter_menu(&mut self, menu_id: usize);
fn exit_menu(&mut self);
fn go(&mut self, menu_id: usize);
pub fn get_deepest_selected_submenu(&self) -> &Menu {
// Use a loop to traverse to the deepest submenu
let mut current_menu = self;
while let Some(ref selected_submenu) = current_menu.selected_submenu {
current_menu = selected_submenu;
}
current_menu
}
}
pub trait App {
fn base(&self) -> &AppBase;
fn base_mut(&mut self) -> &mut AppBase;
// fn main_menu(&self) -> &MainMenu;
}
struct Spotify {
base: AppBase,
}
impl Spotify {
fn new() -> Self {
let spotify_menus = vec![
Menu {
submenus: vec![
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Liked Songs".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Recently Played".to_string(),
},
],
current_submenu_id: 0,
selected_submenu: None,
name: "Playlists".to_string(),
},
Menu {
submenus: vec![
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Mike Oldfield".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "JM. Jarre".to_string(),
},
],
current_submenu_id: 0,
selected_submenu: None,
name: "Artists".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Albums".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Songs".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Genres".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "New Releases".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Charts".to_string(),
},
];
Spotify {
base: AppBase {
name: "Spotify".to_string(),
main_menu: Menu {
submenus: spotify_menus,
current_submenu_id: 0,
selected_submenu: None,
name: "XXX first one unused".to_string(),
},
},
}
}
}
impl App for Spotify {
fn base(&self) -> &AppBase {
&self.base
}
fn base_mut(&mut self) -> &mut AppBase {
&mut self.base
}
}
// Similar implementations for other apps like Radio and Settings
struct Radio {
base: AppBase,
}
impl Radio {
fn new() -> Self {
let radio_menus = vec![
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Favorites".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Local".to_string(),
},
Menu {
submenus: vec![],
current_submenu_id: 0,
selected_submenu: None,
name: "Global".to_string(),
},
];
Radio {
base: AppBase {
name: "Radio".to_string(),
main_menu: Menu {
submenus: radio_menus,
current_submenu_id: 0,
selected_submenu: None,
name: "XXX first one unused".to_string(),
},
},
}
}
}
impl App for Radio {
fn base(&self) -> &AppBase {
&self.base
}
fn base_mut(&mut self) -> &mut AppBase {
&mut self.base
}
fn get_current_view(&self) -> AppView;
}
pub fn get_beo_apps() -> BeoApps {
let apps: Vec<Box<dyn App>> = vec![Box::new(Spotify::new()), Box::new(Radio::new())];
let apps: Vec<Box<dyn BeoApp>> = vec![Box::new(Spotify::new()), Box::new(Radio::new())];
BeoApps { apps }
}

173
src/apps/radio.rs Normal file
View file

@ -0,0 +1,173 @@
use crate::apps::BeoApp;
use mpd::{Client, Song};
use std::net::TcpStream;
use std::fs::read_to_string;
#[derive(Debug, Clone, PartialEq)]
enum RadioMenuState {
Root,
Playing,
Genres,
Genre(String), // (name)
Playlists,
Playlist(String), // (name
}
#[derive(Debug)]
pub struct Radio {
i: i32,
state: RadioMenuState,
breadcrumb_states: Vec<RadioMenuState>,
mpd_client: Option<Client<TcpStream>>,
current_view: Option<crate::apps::AppView>,
online_radios: Vec<OnlineRadio>,
}
#[derive(Debug)]
struct OnlineRadio {
name: String,
url: String,
}
fn get_radios() -> Vec<OnlineRadio> {
let radios = read_to_string("radios.txt").unwrap();
let mut result = vec![];
for line in radios.lines() {
let parts: Vec<&str> = line.split("").collect();
result.push(OnlineRadio {
name: parts[0].to_string(),
url: parts[1].to_string(),
});
}
result
}
impl Radio {
pub fn new() -> Self {
let conn = Client::connect("127.0.0.1:6600").unwrap();
//conn.volume(100).unwrap();
//conn.load("My Lounge Playlist", ..).unwrap();
//conn.play().unwrap();
Radio {
i: 0,
mpd_client: Some(conn),
state: RadioMenuState::Root,
breadcrumb_states: vec![],
current_view: None,
online_radios: get_radios(),
}
}
}
impl BeoApp for Radio {
fn name(&self) -> &str {
"Radio"
}
fn enter_menu(&mut self, menu_id: usize) {
self.breadcrumb_states.push(self.state.clone());
match (&self.state, menu_id) {
(RadioMenuState::Root, _) => {
let url = &self.online_radios[menu_id].url;
// Tell mpd to play this specific radio url:
if self.mpd_client.as_mut().unwrap().status().unwrap().state == mpd::State::Play {
self.mpd_client.as_mut().unwrap().stop();
}
self.mpd_client.as_mut().unwrap().clear().unwrap();
self.mpd_client
.as_mut()
.unwrap()
.push(Song {
file: url.clone(),
..Default::default()
})
.unwrap();
self.mpd_client.as_mut().unwrap().play().unwrap();
self.state = RadioMenuState::Playing;
}
(RadioMenuState::Root, 1) => {
//France Info
self.state = RadioMenuState::Playing;
self.mpd_client.as_mut().unwrap().toggle_pause().unwrap();
}
(RadioMenuState::Root, 2) => {
//Couleur3
self.state = RadioMenuState::Genres;
}
(RadioMenuState::Genres, i) => {
self.state = RadioMenuState::Genre(format!("{}", i));
}
(RadioMenuState::Root, 1) => {
self.state = RadioMenuState::Playlists;
}
(RadioMenuState::Playlists, i) => {
self.state = RadioMenuState::Playlist(format!("{}", i));
}
(RadioMenuState::Genre(i), 0) => {
self.state = RadioMenuState::Genres;
}
_ => {
println!("Invalid state transition");
}
}
println!("Radio2 entered");
println!("Radio2 state: {:?}", self.state);
self.i += 1;
}
fn exit_menu(&mut self) {
println!("Radio2 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) {
println!("Radio2 go");
self.mpd_client.as_mut().unwrap().stop().unwrap();
}
fn get_current_view(&self) -> crate::apps::AppView {
match self.state {
RadioMenuState::Root => {
let mut menus = vec![];
for radio in &self.online_radios {
menus.push(crate::apps::Title {
title: radio.name.clone(),
});
}
return crate::apps::AppView {
title: "Radio".to_string(),
menus,
};
}
RadioMenuState::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

@ -152,22 +152,15 @@ impl Beo5Device {
}
}
}
/*
evdev::Switch::SW_GO => {
evdev::Key::BTN_SELECT => {
if ev.value() == 1 {
return Beo5Event::GoButtonPressed;
} else {
return Beo5Event::GoButtonReleased;
if ev.value() == 1 {
return Some(Beo5Event::GoButtonPressed);
} else {
return Some(Beo5Event::GoButtonReleased);
}
}
}
evdev::Switch::SW_POWER => {
if ev.value() == 1 {
return Beo5Event::PowerButtonPressed;
} else {
return Beo5Event::PowerButtonReleased;
}
}
*/
// Shouldn't be any other switches
_ => {
panic!("Unknown switch event: {ev:?}")

View file

@ -18,6 +18,7 @@ use glutin::prelude::*;
mod apps;
mod hid;
mod roundy_math;
mod spotify;
mod ui;
#[allow(dead_code)]

114
src/spotify.rs Normal file
View file

@ -0,0 +1,114 @@
use crate::apps::BeoApp;
#[derive(Debug, Clone, PartialEq)]
enum SpotifyMenuState {
Root,
Genres,
Genre(String), // (name)
Playlists,
Playlist(String), // (name
}
#[derive(Debug)]
pub struct Spotify {
i: i32,
state: SpotifyMenuState,
breadcrumb_states: Vec<SpotifyMenuState>,
current_view: Option<crate::apps::AppView>,
}
impl Spotify {
pub fn new() -> Self {
Spotify {
i: 0,
state: SpotifyMenuState::Root,
breadcrumb_states: vec![],
current_view: None,
}
}
}
impl BeoApp for Spotify {
fn name(&self) -> &str {
"Spotify"
}
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) {
println!("Spotify2 go");
}
fn get_current_view(&self) -> crate::apps::AppView {
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![],
};
}
}
}
}

201
src/ui.rs
View file

@ -1,8 +1,12 @@
use std::thread::current;
use femtovg::{Baseline, Canvas, Color, Paint, Path, Renderer};
use pulsectl::controllers::DeviceControl;
use pulsectl::controllers::SinkController;
use crate::{hid::Beo5Event, Fonts};
use crate::apps::{App, BeoApps};
use crate::apps::{BeoApp, BeoApps};
use crate::roundy_math;
pub struct BeoUi {
@ -83,11 +87,12 @@ impl BeoUi {
}
if let Some(selected_app) = self.current_app() {
let selected_menu = selected_app.base().main_menu.get_deepest_selected_submenu();
let menu_count = selected_menu.submenus.len();
println!("helol menu_count: {}", menu_count);
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.;
println!("max_angle: {}", max_angle);
if self.angle_shift > max_angle {
self.angle_shift = max_angle;
@ -99,8 +104,11 @@ impl BeoUi {
println!("choose_app_wheel_angle");
let angle = self.angle_shift;
if let Some(selected_app) = self.current_app() {
let actual_menu = selected_app.base().main_menu.get_deepest_selected_submenu();
let menu_count = actual_menu.submenus.len();
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);
@ -120,43 +128,50 @@ impl BeoUi {
}
Beo5Event::LeftButtonPressed => {
println!("Left button pressed. Will select submenu");
let submenu_id = self.get_selected_wheel_angle_menu_id();
match submenu_id {
Some(submenu_id) => {
self.current_app_mut()
.unwrap()
.base_mut()
.enter_submenu(submenu_id);
self.angle_shift = 0.0;
}
None => {
println!("No submenu id found");
let selected_menu_id = self.get_selected_wheel_angle_menu_id();
if let Some(app) = self.current_app_mut() {
match selected_menu_id {
Some(menu_id) => {
app.enter_menu(menu_id);
self.angle_shift = 0.0;
}
None => {
println!("No menu id found");
}
}
}
}
Beo5Event::RightButtonPressed => {
// That means that we get out of a submenu
self.current_app_mut().unwrap().base_mut().exit_submenu();
println!("Right button pressed");
if let Some(app) = self.current_app_mut() {
app.exit_menu();
}
}
Beo5Event::SelectionWheelRel(rel_angle_eps) => {
self.time_without_wheel_spin = 0.0;
self.angle_shift += rel_angle_eps as f32;
self.adjust_wheel_angle();
}
_ => {
Beo5Event::VolumeWheelRel(vol_rel) => {
println!("Volume rel: {}", vol_rel);
let mut sink = SinkController::create().unwrap();
let dev = sink.get_default_device();
if let Ok(dev) = dev {
if vol_rel > 0 {
sink.increase_device_volume_by_percent(dev.index, 0.01);
} else {
sink.decrease_device_volume_by_percent(dev.index, 0.01);
}
}
}
e => {
print!("Unhandled event {:?}", e)
// TODO: pass event to current app
}
}
println!(
"Current submenu: {:?}",
self.current_app_mut()
.unwrap()
.base_mut()
.main_menu
.get_deepest_selected_submenu()
.name
);
if let Some(app) = self.current_app() {
println!("Current app {:?}", app.name());
}
}
pub fn draw<T: Renderer>(&self, canvas: &mut Canvas<T>, fonts: &Fonts) {
@ -188,10 +203,10 @@ impl BeoUi {
self.current_app_id = None;
}
fn current_app(&self) -> Option<&Box<dyn App>> {
fn current_app(&self) -> Option<&Box<dyn BeoApp>> {
self.current_app_id.map(|id| &self.beo_apps.apps[id])
}
fn current_app_mut(&mut self) -> Option<&mut Box<dyn App>> {
fn current_app_mut(&mut self) -> Option<&mut Box<dyn BeoApp>> {
self.current_app_id.map(|id| &mut self.beo_apps.apps[id])
}
@ -234,7 +249,7 @@ impl BeoUi {
};
let app = &apps[appid];
let _ = canvas.fill_text(pts[appid].x, pts[appid].y, app.base().name(), paint);
let _ = canvas.fill_text(pts[appid].x, pts[appid].y, app.name(), paint);
}
// draw the laser
@ -247,8 +262,8 @@ impl BeoUi {
canvas.fill_path(&path, &ellipse_color);
}
fn draw_app<T: Renderer>(&self, canvas: &mut Canvas<T>, fonts: &Fonts, app: &Box<dyn App>) {
let current_app_deepest_menu = &app.base().main_menu.get_deepest_selected_submenu();
fn draw_app<T: Renderer>(&self, canvas: &mut Canvas<T>, fonts: &Fonts, app: &Box<dyn BeoApp>) {
let current_app_menu = app.get_current_view();
let menu_circle = roundy_math::VirtualCircle {
center: roundy_math::Point {
@ -258,14 +273,11 @@ impl BeoUi {
radius: MENU_CIRCLE_RADIUS,
};
for i in 0..current_app_deepest_menu.submenus.len() {
for i in 0..current_app_menu.menus.len() {
let angle = i as f32 * -ANGLE_DEG_BETWEEN_MENU_ITEMS + self.angle_shift;
if angle > -90. && angle < 90. {
let pos = menu_circle.get_point_from_angle_bcircle(angle);
let n = format!(
"{}: {} ({}°)",
i, current_app_deepest_menu.submenus[i].name, angle
);
let n = format!("{}: {} ({}°)", i, current_app_menu.menus[i].title, angle);
let _ = canvas.fill_text(
pos.x,
pos.y,
@ -275,114 +287,5 @@ impl BeoUi {
continue;
}
}
/*
let menus_count = current_app_deepest_menu.submenus.len();
let menu_circle = roundy_math::VirtualCircle {
center: roundy_math::Point {
x: canvas_width as f32,
y: canvas_height as f32 / 2.0,
},
radius: MENU_CIRCLE_RADIUS,
};
let canvas_size = roundy_math::Point {
x: canvas_width as f32,
y: canvas_height as f32,
};
// draw the main apps in the circle
let apps = &self.beo_apps.apps;
let pts = laser_menu_circle.get_equidistant_points(apps.len(), canvas_size);
// XXX To be taken from global struct
let mut paint_normal = Paint::color(Color::hex("B7410E"));
paint_normal.set_font(&[fonts.sans]);
paint_normal.set_text_baseline(Baseline::Top);
let mut paint_selected = Paint::color(Color::hex("D7612E"));
paint_selected.set_font(&[fonts.bold]);
paint_selected.set_text_baseline(Baseline::Top);
for appid in 0..apps.len() {
let paint;
if self.current_app_id == Some(appid) {
paint = &paint_selected;
} else {
paint = &paint_normal;
}
let app = &apps[appid];
let _ = canvas.fill_text(pts[appid].x, pts[appid].y, app.base().name(), paint);
}
// draw the laser
let ellipse_color = Paint::color(Color::hex("5C89D188"));
let mut path = Path::new();
let ey = laser_pct_to_y_pos(self.laser_pct);
let ex = laser_menu_circle.get_x_on_circle(ey);
path.ellipse(ex + 15., ey, 30., 10.);
canvas.fill_path(&path, &ellipse_color);
*/
}
/*
let num_menu_elements_before = 1;
let num_menu_elements_after = 2;
// That means max 1 + >1< + 2 = 4 elements in total
// Minimum aronud 3: 0 + >1< + 2
let current_menu_id = app.base().main_menu.selected_id;
let menu_elements = &app.base().main_menu.names;
// Calculate indices for slices
let start_before =
(current_menu_id as isize - num_menu_elements_before as isize).max(0) as usize;
let end_before = current_menu_id;
let start_after = current_menu_id + 1;
let end_after =
((current_menu_id + 1 + num_menu_elements_after).min(menu_elements.len())) as usize;
// Safely getting slices using clamping
let menu_elems_before = &menu_elements[start_before..end_before];
let menu_elem_selected = &menu_elements[current_menu_id];
let menu_elems_after = &menu_elements[start_after..end_after];
let mut toti = 0.;
for i in 0..num_menu_elements_before {
// This is a special case: we reserve some space
//so that the current menu is always at the same place
if i < menu_elems_before.len() {
let _ = canvas.fill_text(
toti * 100. + 50.,
CANVAS_HEIGHT - 80.,
&menu_elems_before[i],
&fonts.app_menu,
);
}
toti += 1.;
}
let _ = canvas.fill_text(
toti * 100. + 50.,
CANVAS_HEIGHT - 80.,
&menu_elem_selected,
&fonts.app_menu_selected,
);
toti += 1.;
for i in 0..menu_elems_after.len() {
let _ = canvas.fill_text(
toti * 100. + 50.,
CANVAS_HEIGHT - 80.,
&menu_elems_after[i],
&fonts.app_menu,
);
toti += 1.;
}
*/
}