beautify scan menu

This commit is contained in:
2026-08-15 00:17:37 +02:00
parent 890a0e5d62
commit 9792385af1
2 changed files with 42 additions and 25 deletions
+2
View File
@@ -1,3 +1,4 @@
use crate::navigation::scan_menu::ScanMenu;
use crate::navigation::state::{Menu, NavigationState}; use crate::navigation::state::{Menu, NavigationState};
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs}; use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
@@ -28,6 +29,7 @@ pub trait Navigable {
#[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 = NavigationState::default(); let mut state = NavigationState::default();
// state.current_screen = Menu::Scan(ScanMenu { progress: (100 * 30 / 255) as u8 });
log::info!("starting navigation"); log::info!("starting navigation");
loop { loop {
+40 -25
View File
@@ -4,14 +4,16 @@ use alloc::format;
use embedded_graphics::Drawable; use embedded_graphics::Drawable;
use embedded_graphics::geometry::AngleUnit as _; use embedded_graphics::geometry::AngleUnit as _;
use embedded_graphics::geometry::Dimensions as _; use embedded_graphics::geometry::Dimensions as _;
use embedded_graphics::geometry::Size;
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;
use embedded_graphics::primitives::Arc; use embedded_graphics::primitives::Arc;
use embedded_graphics::primitives::Primitive as _; use embedded_graphics::primitives::Primitive as _;
use embedded_graphics::primitives::PrimitiveStyleBuilder; use embedded_graphics::primitives::PrimitiveStyleBuilder;
use embedded_graphics::primitives::Rectangle;
use embedded_graphics::primitives::StrokeAlignment; use embedded_graphics::primitives::StrokeAlignment;
use embedded_graphics::text::Alignment; use embedded_graphics::text::Alignment;
use embedded_graphics::text::Baseline; use embedded_graphics::text::Baseline;
@@ -19,11 +21,12 @@ use embedded_graphics::text::Text;
use embedded_graphics::text::TextStyleBuilder; use embedded_graphics::text::TextStyleBuilder;
use embedded_graphics_core::draw_target::DrawTarget; use embedded_graphics_core::draw_target::DrawTarget;
use super::navigation::Action;
use super::state::Menu; use super::state::Menu;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct ScanMenu { pub struct ScanMenu {
progress: u8, // 0..255 pub progress: u8, // 0..255
} }
impl super::navigation::Navigable for ScanMenu { impl super::navigation::Navigable for ScanMenu {
@@ -31,9 +34,12 @@ impl super::navigation::Navigable for ScanMenu {
&self, &self,
display: &mut PrimaryLcdDisplay<'static>, display: &mut PrimaryLcdDisplay<'static>,
) -> impl core::future::Future<Output = ()> + Send { ) -> impl core::future::Future<Output = ()> + Send {
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE); let style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
display.clear(Rgb565::BLACK).unwrap();
Text::new("Scanning...", Point::new(20, 240), style) let display_area = display.bounding_box();
Text::new("Scanning...", Point::new(20, 30), style)
.draw(display) .draw(display)
.unwrap(); .unwrap();
@@ -43,40 +49,49 @@ impl super::navigation::Navigable for ScanMenu {
.stroke_width(5) .stroke_width(5)
.stroke_alignment(StrokeAlignment::Inside) .stroke_alignment(StrokeAlignment::Inside)
.build(); .build();
let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE); let character_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let text_style = TextStyleBuilder::new() let text_style = TextStyleBuilder::new()
.baseline(Baseline::Middle) .baseline(Baseline::Middle)
.alignment(Alignment::Center) .alignment(Alignment::Center)
.build(); .build();
display.clear(Rgb565::BLACK).unwrap(); let sweep = self.progress as f32 * 360.0 / 255.0;
let sweep = self.progress as f32 * 360.0 / 100.0;
let width = display_area.size.width;
let bounding_box =
Rectangle::with_center(display_area.center(), Size::new_equal(4 * width / 5));
// log::info!("bounding_box: {:?}", bounding_box);
// log::info!("display_area: {:?}", display_area);
// Draw an arc with a 5px wide stroke. // Draw an arc with a 5px wide stroke.
Arc::new(Point::new(2, 2), 64 - 4, 90.0.deg(), sweep.deg()) Arc::new(
.into_styled(arc_stroke) bounding_box.top_left,
.draw(display) bounding_box.size.width,
.unwrap(); 90.0.deg(),
sweep.deg(),
// Draw centered text.
let text = format!("{}%", self.progress);
Text::with_text_style(
&text,
display.bounding_box().center(),
character_style,
text_style,
) )
.into_styled(arc_stroke)
.draw(display) .draw(display)
.unwrap(); .unwrap();
// Draw centered text.
let text = format!("{:.2}%", 100. * (self.progress as f32) / 255.);
Text::with_text_style(&text, display_area.center(), character_style, text_style)
.draw(display)
.unwrap();
core::future::ready(()) core::future::ready(())
} }
fn handle_input( fn handle_input(&self, input: Action) -> impl core::future::Future<Output = Menu> + Send {
&self, async move {
_input: super::navigation::Action, let new_progress = match input {
) -> impl core::future::Future<Output = Menu> + Send { Action::Up => self.progress.wrapping_add(5),
core::future::ready(Menu::Scan(self.clone())) _ => self.progress,
};
Menu::Scan(ScanMenu {
progress: new_progress,
})
}
} }
} }