main menu: wrap around correctly
This commit is contained in:
@@ -2,7 +2,7 @@ use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs}
|
|||||||
|
|
||||||
use alloc::format;
|
use alloc::format;
|
||||||
use embedded_graphics::mono_font::MonoTextStyle;
|
use embedded_graphics::mono_font::MonoTextStyle;
|
||||||
use embedded_graphics::mono_font::ascii::FONT_6X10;
|
use embedded_graphics::mono_font::ascii::FONT_10X20;
|
||||||
use embedded_graphics::pixelcolor::Rgb565;
|
use embedded_graphics::pixelcolor::Rgb565;
|
||||||
use embedded_graphics::prelude::Point;
|
use embedded_graphics::prelude::Point;
|
||||||
use embedded_graphics::prelude::RgbColor;
|
use embedded_graphics::prelude::RgbColor;
|
||||||
@@ -17,13 +17,16 @@ pub struct MainMenu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl super::navigation::Displayable for MainMenu {
|
impl super::navigation::Displayable for MainMenu {
|
||||||
fn display(&self, display: &mut PrimaryLcdDisplay<'static>) -> impl core::future::Future<Output = ()> + Send {
|
fn display(
|
||||||
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
&self,
|
||||||
let selected_style = MonoTextStyle::new(&FONT_6X10, Rgb565::BLUE);
|
display: &mut PrimaryLcdDisplay<'static>,
|
||||||
|
) -> impl core::future::Future<Output = ()> + Send {
|
||||||
|
let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
|
||||||
|
let selected_style = MonoTextStyle::new(&FONT_10X20, Rgb565::BLUE);
|
||||||
|
|
||||||
Text::new(
|
Text::new(
|
||||||
&format!("Last card"),
|
&format!("Last card"),
|
||||||
Point::new(20, 240),
|
Point::new(40, 40),
|
||||||
if self.selected == 0 {
|
if self.selected == 0 {
|
||||||
selected_style
|
selected_style
|
||||||
} else {
|
} else {
|
||||||
@@ -35,7 +38,7 @@ impl super::navigation::Displayable for MainMenu {
|
|||||||
|
|
||||||
Text::new(
|
Text::new(
|
||||||
&format!("Journal"),
|
&format!("Journal"),
|
||||||
Point::new(20, 250),
|
Point::new(40, 60),
|
||||||
if self.selected == 1 {
|
if self.selected == 1 {
|
||||||
selected_style
|
selected_style
|
||||||
} else {
|
} else {
|
||||||
@@ -47,8 +50,8 @@ impl super::navigation::Displayable for MainMenu {
|
|||||||
|
|
||||||
Text::new(
|
Text::new(
|
||||||
&format!("Settings"),
|
&format!("Settings"),
|
||||||
Point::new(20, 260),
|
Point::new(40, 80),
|
||||||
if self.selected == 1 {
|
if self.selected == 2 {
|
||||||
selected_style
|
selected_style
|
||||||
} else {
|
} else {
|
||||||
style
|
style
|
||||||
|
|||||||
@@ -8,13 +8,17 @@ use embassy_time::{Duration, Timer};
|
|||||||
const DEBOUNCE_DURATION_MILLIS: u64 = 100;
|
const DEBOUNCE_DURATION_MILLIS: u64 = 100;
|
||||||
|
|
||||||
pub trait Displayable {
|
pub trait Displayable {
|
||||||
fn display(&self, display: &mut PrimaryLcdDisplay<'static>) -> impl core::future::Future<Output = ()> + Send;
|
fn display(
|
||||||
|
&self,
|
||||||
|
display: &mut PrimaryLcdDisplay<'static>,
|
||||||
|
) -> impl core::future::Future<Output = ()> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
|
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
|
||||||
let mut state = MainMenu { selected: 0 };
|
let mut state = MainMenu { selected: 0 };
|
||||||
|
|
||||||
|
state.display(display).await;
|
||||||
log::info!("starting navigation");
|
log::info!("starting navigation");
|
||||||
loop {
|
loop {
|
||||||
log::info!("await button press");
|
log::info!("await button press");
|
||||||
@@ -32,7 +36,11 @@ pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'st
|
|||||||
let value = match selection {
|
let value = match selection {
|
||||||
Either6::First(_) => {
|
Either6::First(_) => {
|
||||||
log::info!("up pressed");
|
log::info!("up pressed");
|
||||||
(state.selected.wrapping_sub(1)) % MAX_SELECTED
|
if (state.selected - 1) < 0 {
|
||||||
|
MAX_SELECTED - 1
|
||||||
|
} else {
|
||||||
|
state.selected - 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Either6::Second(_) => {
|
Either6::Second(_) => {
|
||||||
log::info!("down pressed");
|
log::info!("down pressed");
|
||||||
|
|||||||
Reference in New Issue
Block a user