use crate::display::primary_lcd::PrimaryLcdDisplay; use alloc::format; use embedded_graphics::Drawable; use embedded_graphics::geometry::AngleUnit as _; use embedded_graphics::geometry::Dimensions as _; use embedded_graphics::mono_font::MonoTextStyle; use embedded_graphics::mono_font::ascii::FONT_6X10; use embedded_graphics::pixelcolor::Rgb565; use embedded_graphics::prelude::Point; use embedded_graphics::prelude::RgbColor; use embedded_graphics::primitives::Arc; use embedded_graphics::primitives::Primitive as _; use embedded_graphics::primitives::PrimitiveStyleBuilder; use embedded_graphics::primitives::StrokeAlignment; use embedded_graphics::text::Alignment; use embedded_graphics::text::Baseline; use embedded_graphics::text::Text; use embedded_graphics::text::TextStyleBuilder; use embedded_graphics_core::draw_target::DrawTarget; pub struct ScanMenu { progress: u8, // 0..255 } impl super::navigation::Displayable for ScanMenu { fn display( &self, display: &mut PrimaryLcdDisplay<'static>, ) -> impl core::future::Future + Send { let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE); Text::new("Scanning...", Point::new(20, 240), style) .draw(display) .unwrap(); // Create styles used by the drawing operations. let arc_stroke = PrimitiveStyleBuilder::new() .stroke_color(Rgb565::WHITE) .stroke_width(5) .stroke_alignment(StrokeAlignment::Inside) .build(); let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE); let text_style = TextStyleBuilder::new() .baseline(Baseline::Middle) .alignment(Alignment::Center) .build(); display.clear(Rgb565::BLACK).unwrap(); let sweep = self.progress as f32 * 360.0 / 100.0; // Draw an arc with a 5px wide stroke. Arc::new(Point::new(2, 2), 64 - 4, 90.0.deg(), sweep.deg()) .into_styled(arc_stroke) .draw(display) .unwrap(); // Draw centered text. let text = format!("{}%", self.progress); Text::with_text_style( &text, display.bounding_box().center(), character_style, text_style, ) .draw(display) .unwrap(); core::future::ready(()) } }