@benjamin.brienen held
This commit is contained in:
@@ -3,65 +3,34 @@ pub(super) mod widgets;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
draw_target::DrawTarget,
|
||||
mono_font::{MonoTextStyle, ascii::FONT_6X10},
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::Point,
|
||||
text::{Alignment, Baseline, LineHeight, Text, TextStyle, TextStyleBuilder},
|
||||
};
|
||||
use g13_driver::{G13Event, Vec2};
|
||||
use g13_driver::{G13, G13Event};
|
||||
|
||||
use crate::app::pages::StartPage;
|
||||
|
||||
use super::app::widgets::Page;
|
||||
|
||||
type Color = BinaryColor;
|
||||
|
||||
const CHARACTER_STYLE: MonoTextStyle<'static, BinaryColor> =
|
||||
MonoTextStyle::new(&FONT_6X10, BinaryColor::On);
|
||||
|
||||
const TEXT_STYLE: TextStyle = TextStyleBuilder::new()
|
||||
.baseline(Baseline::Top)
|
||||
.alignment(Alignment::Left)
|
||||
.build();
|
||||
|
||||
pub struct App {
|
||||
pages: VecDeque<Box<dyn Page>>,
|
||||
joy: Vec2<f32>,
|
||||
pages: VecDeque<Box<dyn Page<Display = G13>>>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
pages: VecDeque::new(),
|
||||
joy: Vec2::new(0.0, 0.0),
|
||||
}
|
||||
let mut pages: VecDeque<Box<dyn Page<Display = G13>>> = VecDeque::new();
|
||||
|
||||
pages.push_back(Box::new(StartPage::default()));
|
||||
|
||||
Self { pages }
|
||||
}
|
||||
|
||||
pub fn update(&mut self, event: G13Event) {
|
||||
match event {
|
||||
G13Event::Axis(x, y) => {
|
||||
self.joy.x = x;
|
||||
self.joy.y = y;
|
||||
}
|
||||
G13Event::Button(_button, (_prev, _value)) => { /* noop */ }
|
||||
if let Some(last_page) = self.pages.iter_mut().last() {
|
||||
last_page.update(event);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw<D>(&mut self, display: &mut D)
|
||||
where
|
||||
D: DrawTarget<Color = Color>,
|
||||
{
|
||||
if let Some(last_page) = self.pages.iter().last() {
|
||||
pub fn draw(&mut self, display: &mut G13) {
|
||||
if let Some(last_page) = self.pages.iter_mut().last() {
|
||||
last_page.draw(display);
|
||||
}
|
||||
|
||||
// let string = format!(
|
||||
// "{}x{}",
|
||||
// (self.joy.x * 256.0) as i32,
|
||||
// (self.joy.y * 256.0) as i32
|
||||
// );
|
||||
// let text = Text::with_text_style(&string, Point::new(1, 1), CHARACTER_STYLE, TEXT_STYLE);
|
||||
// let _ = text.draw(display);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user