use crate::drivers::primary_lcd::PrimaryDisplayError; use crate::navigation::navigation::Action; use crate::navigation::navigation::Navigable; use crate::navigation::navigation::NewState; use crate::navigation::outputs::Outputs; use crate::peripherals::Peripherals; use crate::views::view::View; use alloc::boxed::Box; use core::error; use embedded_graphics::prelude::Point; use embedded_graphics::{ Drawable, mono_font::{MonoTextStyle, ascii::FONT_10X20}, pixelcolor::Rgb565, prelude::*, primitives::Rectangle, }; use alloc::format; use embedded_text::{ TextBox, alignment::HorizontalAlignment, style::{HeightMode, TextBoxStyleBuilder}, }; #[derive(Debug, Clone)] pub struct FlashInfoView {} impl Navigable for FlashInfoView { fn display( &self, outputs: &mut Outputs, peripherals: &Peripherals, ) -> impl core::future::Future>> + Send { async move { outputs .primary_display .clear(Rgb565::BLACK) .map_err(PrimaryDisplayError::from)?; let _style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE); let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE); let textbox_style = TextBoxStyleBuilder::new() .height_mode(HeightMode::FitToText) .alignment(HorizontalAlignment::Justified) .build(); let display_area = outputs.primary_display.bounding_box(); let bounds = Rectangle::new(Point::new(0, 30), display_area.size); log::debug!("locking store"); let store = peripherals.store.lock().await; log::debug!("getting card count"); let card_count = store.card_store.load_card_count().await?; TextBox::with_textbox_style( &format!( " Card Count: {}\n ", card_count ), bounds, style, textbox_style, ) .draw(&mut outputs.primary_display) .map_err(PrimaryDisplayError::from)?; Ok(()) } } fn handle_input(&self, input: Action) -> impl core::future::Future + Send { async move { let new_menu = View::FlashInfo(self.clone()); match input { Action::Button(_) => NewState { replace_view: matches!(new_menu, View::FlashInfo(_)), view: new_menu, redraw: true, }, Action::Timer => { // Skip timer inputs NewState { view: new_menu, replace_view: true, redraw: false, } } } } } }