app menu: always keep current at the same place

Signed-off-by: Frank Villaro-Dixon <frank@villaro-dixon.eu>
This commit is contained in:
Frank Villaro-Dixon 2024-05-16 15:27:25 +02:00
parent 0cae87ce18
commit 697fa281cc

View file

@ -149,18 +149,6 @@ impl BeoUi {
} }
fn draw_app<T: Renderer>(&self, canvas: &mut Canvas<T>, fonts: &Fonts, app: &Box<dyn App>) { fn draw_app<T: Renderer>(&self, canvas: &mut Canvas<T>, fonts: &Fonts, app: &Box<dyn App>) {
/*
let biggest_menu_name = app
.base()
.main_menu
.names
.iter()
.max_by_key(|x| x.len())
.unwrap();
let menu_separated_px = biggest_menu_name.len() as f32 * 8.;
*/
let num_menu_elements_before = 1; let num_menu_elements_before = 1;
let num_menu_elements_after = 2; let num_menu_elements_after = 2;
// That means max 1 + >1< + 2 = 4 elements in total // That means max 1 + >1< + 2 = 4 elements in total
@ -187,13 +175,17 @@ impl BeoUi {
//println!("menu_elems_after: {:?}", menu_elems_after); //println!("menu_elems_after: {:?}", menu_elems_after);
let mut toti = 0.; let mut toti = 0.;
for i in 0..menu_elems_before.len() { 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( let _ = canvas.fill_text(
toti * 100. + 50., toti * 100. + 50.,
CANVAS_HEIGHT - 80., CANVAS_HEIGHT - 80.,
&menu_elems_before[i], &menu_elems_before[i],
&fonts.app_menu, &fonts.app_menu,
); );
}
toti += 1.; toti += 1.;
} }