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 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::prelude::Point;
|
||||
use embedded_graphics::prelude::RgbColor;
|
||||
@@ -17,13 +17,16 @@ pub struct MainMenu {
|
||||
}
|
||||
|
||||
impl super::navigation::Displayable for MainMenu {
|
||||
fn display(&self, display: &mut PrimaryLcdDisplay<'static>) -> impl core::future::Future<Output = ()> + Send {
|
||||
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||
let selected_style = MonoTextStyle::new(&FONT_6X10, Rgb565::BLUE);
|
||||
fn display(
|
||||
&self,
|
||||
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(
|
||||
&format!("Last card"),
|
||||
Point::new(20, 240),
|
||||
Point::new(40, 40),
|
||||
if self.selected == 0 {
|
||||
selected_style
|
||||
} else {
|
||||
@@ -35,7 +38,7 @@ impl super::navigation::Displayable for MainMenu {
|
||||
|
||||
Text::new(
|
||||
&format!("Journal"),
|
||||
Point::new(20, 250),
|
||||
Point::new(40, 60),
|
||||
if self.selected == 1 {
|
||||
selected_style
|
||||
} else {
|
||||
@@ -47,8 +50,8 @@ impl super::navigation::Displayable for MainMenu {
|
||||
|
||||
Text::new(
|
||||
&format!("Settings"),
|
||||
Point::new(20, 260),
|
||||
if self.selected == 1 {
|
||||
Point::new(40, 80),
|
||||
if self.selected == 2 {
|
||||
selected_style
|
||||
} else {
|
||||
style
|
||||
|
||||
@@ -8,13 +8,17 @@ use embassy_time::{Duration, Timer};
|
||||
const DEBOUNCE_DURATION_MILLIS: u64 = 100;
|
||||
|
||||
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]
|
||||
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
|
||||
let mut state = MainMenu { selected: 0 };
|
||||
|
||||
state.display(display).await;
|
||||
log::info!("starting navigation");
|
||||
loop {
|
||||
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 {
|
||||
Either6::First(_) => {
|
||||
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(_) => {
|
||||
log::info!("down pressed");
|
||||
|
||||
Reference in New Issue
Block a user