122 lines
3.8 KiB
Rust
122 lines
3.8 KiB
Rust
use crate::display::sprite::render_sprite_onto_ili9341;
|
|
use crate::drivers::primary_lcd::PrimaryDisplayError;
|
|
use crate::navigation::navigation::NewState;
|
|
use crate::navigation::outputs::Outputs;
|
|
use crate::peripherals::Peripherals;
|
|
use alloc::boxed::Box;
|
|
use alloc::format;
|
|
use core::error;
|
|
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::text::Text;
|
|
use embedded_graphics::{Drawable, geometry::Size, primitives::Rectangle};
|
|
use embedded_graphics_core::draw_target::DrawTarget;
|
|
|
|
use core::future;
|
|
|
|
use crate::{
|
|
card::model::{Card, Palette},
|
|
navigation::navigation::{Action, Navigable},
|
|
views::view::View,
|
|
};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct CardView {
|
|
pub card: Card,
|
|
}
|
|
|
|
impl Navigable for CardView {
|
|
fn display(
|
|
&self,
|
|
outputs: &mut Outputs,
|
|
_: &Peripherals,
|
|
) -> impl core::future::Future<Output = Result<(), Box<dyn error::Error>>> + Send {
|
|
async move {
|
|
let display = &mut outputs.primary_display;
|
|
display
|
|
.clear(Rgb565::BLACK)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
|
|
let background = Rectangle::new(Point::new(0, 0), Size::new(240, 320));
|
|
let bg_color = self.card.cardtype.clone().into();
|
|
|
|
let _ = display.fill_solid(&background, bg_color);
|
|
|
|
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
|
Text::new(
|
|
&format!("Name: {}", self.card.name),
|
|
Point::new(20, 240),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("Type: {}", self.card.cardtype),
|
|
Point::new(20, 250),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("Event: {}", self.card.event),
|
|
Point::new(20, 260),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("UUID: {}", self.card.uuid),
|
|
Point::new(20, 270),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("Trait1: {}", self.card.trait1),
|
|
Point::new(20, 280),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("Trait2: {}", self.card.trait2),
|
|
Point::new(20, 290),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("Trait3: {}", self.card.trait3),
|
|
Point::new(20, 300),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
Text::new(
|
|
&format!("Secret: {}", self.card.secret),
|
|
Point::new(20, 310),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.map_err(PrimaryDisplayError::from)?;
|
|
|
|
let palette: Palette = self.card.cardtype.clone().into();
|
|
render_sprite_onto_ili9341(display, self.card.sprite.data.as_slice(), &palette);
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = NewState> + Send {
|
|
let new_state = NewState {
|
|
view: View::Card(self.clone()),
|
|
replace_view: true,
|
|
redraw: !matches!(input, Action::Timer),
|
|
};
|
|
|
|
future::ready(new_state)
|
|
}
|
|
}
|