beautify scan menu
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use crate::navigation::scan_menu::ScanMenu;
|
||||
use crate::navigation::state::{Menu, NavigationState};
|
||||
use crate::{display::primary_lcd::PrimaryLcdDisplay, navigation::inputs::Inputs};
|
||||
|
||||
@@ -28,6 +29,7 @@ pub trait Navigable {
|
||||
#[embassy_executor::task]
|
||||
pub async fn run(mut inputs: Inputs, display: &'static mut PrimaryLcdDisplay<'static>) {
|
||||
let mut state = NavigationState::default();
|
||||
// state.current_screen = Menu::Scan(ScanMenu { progress: (100 * 30 / 255) as u8 });
|
||||
|
||||
log::info!("starting navigation");
|
||||
loop {
|
||||
|
||||
+36
-21
@@ -4,14 +4,16 @@ use alloc::format;
|
||||
use embedded_graphics::Drawable;
|
||||
use embedded_graphics::geometry::AngleUnit as _;
|
||||
use embedded_graphics::geometry::Dimensions as _;
|
||||
use embedded_graphics::geometry::Size;
|
||||
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;
|
||||
use embedded_graphics::primitives::Arc;
|
||||
use embedded_graphics::primitives::Primitive as _;
|
||||
use embedded_graphics::primitives::PrimitiveStyleBuilder;
|
||||
use embedded_graphics::primitives::Rectangle;
|
||||
use embedded_graphics::primitives::StrokeAlignment;
|
||||
use embedded_graphics::text::Alignment;
|
||||
use embedded_graphics::text::Baseline;
|
||||
@@ -19,11 +21,12 @@ use embedded_graphics::text::Text;
|
||||
use embedded_graphics::text::TextStyleBuilder;
|
||||
use embedded_graphics_core::draw_target::DrawTarget;
|
||||
|
||||
use super::navigation::Action;
|
||||
use super::state::Menu;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ScanMenu {
|
||||
progress: u8, // 0..255
|
||||
pub progress: u8, // 0..255
|
||||
}
|
||||
|
||||
impl super::navigation::Navigable for ScanMenu {
|
||||
@@ -31,9 +34,12 @@ impl super::navigation::Navigable for ScanMenu {
|
||||
&self,
|
||||
display: &mut PrimaryLcdDisplay<'static>,
|
||||
) -> 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)
|
||||
.unwrap();
|
||||
|
||||
@@ -43,40 +49,49 @@ impl super::navigation::Navigable for ScanMenu {
|
||||
.stroke_width(5)
|
||||
.stroke_alignment(StrokeAlignment::Inside)
|
||||
.build();
|
||||
let character_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||
let character_style = MonoTextStyle::new(&FONT_10X20, 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;
|
||||
let sweep = self.progress as f32 * 360.0 / 255.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.
|
||||
Arc::new(Point::new(2, 2), 64 - 4, 90.0.deg(), sweep.deg())
|
||||
Arc::new(
|
||||
bounding_box.top_left,
|
||||
bounding_box.size.width,
|
||||
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,
|
||||
)
|
||||
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(())
|
||||
}
|
||||
|
||||
fn handle_input(
|
||||
&self,
|
||||
_input: super::navigation::Action,
|
||||
) -> impl core::future::Future<Output = Menu> + Send {
|
||||
core::future::ready(Menu::Scan(self.clone()))
|
||||
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = Menu> + Send {
|
||||
async move {
|
||||
let new_progress = match input {
|
||||
Action::Up => self.progress.wrapping_add(5),
|
||||
_ => self.progress,
|
||||
};
|
||||
|
||||
Menu::Scan(ScanMenu {
|
||||
progress: new_progress,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user