111 lines
3.0 KiB
Rust
111 lines
3.0 KiB
Rust
use crate::display::sprite::render_sprite_onto_ili9341;
|
|
use alloc::{format, string::String};
|
|
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},
|
|
display::primary_lcd::PrimaryLcdDisplay,
|
|
navigation::navigation::{Action, Navigable},
|
|
views::view::View,
|
|
};
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct CardView {
|
|
pub card: Card,
|
|
}
|
|
|
|
impl Navigable for CardView {
|
|
fn display(
|
|
&self,
|
|
display: &mut PrimaryLcdDisplay<'static>,
|
|
) -> impl core::future::Future<Output = ()> + Send {
|
|
display.clear(Rgb565::BLACK).unwrap();
|
|
|
|
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)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("Type: {}", self.card.cardtype),
|
|
Point::new(20, 250),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("Event: {}", self.card.event),
|
|
Point::new(20, 260),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("UUID: {}", self.card.uuid),
|
|
Point::new(20, 270),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("Trait1: {}", self.card.trait1),
|
|
Point::new(20, 280),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("Trait2: {}", self.card.trait2),
|
|
Point::new(20, 290),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("Trait3: {}", self.card.trait3),
|
|
Point::new(20, 300),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
Text::new(
|
|
&format!("Secret: {}", self.card.secret),
|
|
Point::new(20, 310),
|
|
style,
|
|
)
|
|
.draw(display)
|
|
.unwrap();
|
|
|
|
let palette: Palette = self.card.cardtype.clone().into();
|
|
render_sprite_onto_ili9341(display, self.card.sprite.data.as_slice(), &palette);
|
|
|
|
core::future::ready(())
|
|
}
|
|
|
|
fn handle_input(&self, input: Action) -> impl core::future::Future<Output = View> + Send {
|
|
let new_menu = match input {
|
|
Action::Ok => View::Card(self.clone()),
|
|
_ => View::Card(self.clone()),
|
|
};
|
|
|
|
future::ready(new_menu)
|
|
}
|
|
}
|