Can i haz Structure?
This commit is contained in:
@@ -4,7 +4,7 @@ version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[dependencies]
|
||||
# buoyant = "0.6.1"
|
||||
crossbeam-channel.workspace = true
|
||||
ctrlc = "3.5"
|
||||
embedded-graphics = "0.8"
|
||||
g13-driver.workspace = true
|
||||
@@ -12,3 +12,4 @@ mlua = { version = "0.11.6", features = ["lua54", "async", "macros", "serde"] }
|
||||
time = { version = "0.3.47", features = ["formatting", "macros"] }
|
||||
|
||||
embedded-graphics-simulator = "0.7.0"
|
||||
winit = "0.30.12"
|
||||
|
||||
34
g13-os/src/app/mod.rs
Normal file
34
g13-os/src/app/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
pub(super) mod pages;
|
||||
pub(super) mod widgets;
|
||||
|
||||
use std::collections::VecDeque;
|
||||
|
||||
use embedded_graphics::{pixelcolor::BinaryColor, prelude::DrawTarget};
|
||||
use g13_driver::G13Event;
|
||||
|
||||
use super::app::widgets::Page;
|
||||
|
||||
type Color = BinaryColor;
|
||||
|
||||
pub struct App {
|
||||
pages: VecDeque<Box<dyn Page>>,
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
pages: VecDeque::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, event: G13Event) {
|
||||
println!("{:?}", event);
|
||||
}
|
||||
|
||||
pub fn draw<D>(&mut self, display: &mut D) -> Result<(), Box<dyn std::error::Error>>
|
||||
where
|
||||
D: DrawTarget<Color = Color>,
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
0
g13-os/src/app/pages/mod.rs
Normal file
0
g13-os/src/app/pages/mod.rs
Normal file
2
g13-os/src/app/widgets/mod.rs
Normal file
2
g13-os/src/app/widgets/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub trait Page: Widget {}
|
||||
pub trait Widget {}
|
||||
@@ -1,73 +1,40 @@
|
||||
// pub mod mouse;
|
||||
// mod os;
|
||||
mod app;
|
||||
|
||||
// use embedded_graphics::prelude::{Dimensions, DrawTarget};
|
||||
// use embedded_graphics::{pixelcolor::BinaryColor, prelude::Size};
|
||||
// use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
|
||||
// use mlua::{Error, ExternalResult, Lua};
|
||||
// use rsact_ui::prelude::*;
|
||||
// use rsact_ui::{
|
||||
// col,
|
||||
// event::simulator::simulator_single_encoder,
|
||||
// render::{AntiAliasing, RendererOptions},
|
||||
// row,
|
||||
// style::accent::AccentStyler,
|
||||
// ui::UI,
|
||||
// };
|
||||
// use std::fmt::Binary;
|
||||
// use std::{
|
||||
// fs,
|
||||
// sync::{
|
||||
// Arc,
|
||||
// atomic::{AtomicBool, Ordering},
|
||||
// },
|
||||
// thread::sleep,
|
||||
// time::{Duration, Instant},
|
||||
// };
|
||||
|
||||
// use crate::os::G13Os;
|
||||
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
pixelcolor::BinaryColor,
|
||||
prelude::{DrawTarget, Point},
|
||||
use std::{
|
||||
thread::sleep,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
use g13_driver::{G13, G13Event};
|
||||
|
||||
use embedded_graphics::pixelcolor::BinaryColor;
|
||||
use embedded_graphics::prelude::*;
|
||||
|
||||
use g13_driver::G13;
|
||||
|
||||
use crate::app::App;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let g13 = G13::new()?;
|
||||
let (mut display, input) = g13.split();
|
||||
let mut g13 = G13::new()?;
|
||||
|
||||
let character_style = embedded_graphics::mono_font::MonoTextStyle::new(
|
||||
&embedded_graphics::mono_font::ascii::FONT_10X20,
|
||||
embedded_graphics::pixelcolor::BinaryColor::On,
|
||||
);
|
||||
let textstyle = embedded_graphics::text::TextStyleBuilder::new()
|
||||
.alignment(embedded_graphics::text::Alignment::Left)
|
||||
.baseline(embedded_graphics::text::Baseline::Top)
|
||||
.build();
|
||||
let mut app = App::new();
|
||||
|
||||
for event in input {
|
||||
let Some(event) = event else {
|
||||
continue;
|
||||
};
|
||||
let events = g13.events();
|
||||
|
||||
println!("{:?}", event);
|
||||
loop {
|
||||
let start = Instant::now();
|
||||
if let Ok(event) = events.try_recv() {
|
||||
app.update(event);
|
||||
}
|
||||
g13.clear(BinaryColor::Off)?;
|
||||
|
||||
display.clear(BinaryColor::Off)?;
|
||||
|
||||
if let G13Event::Axis(x, y) = event {
|
||||
embedded_graphics::text::Text::with_text_style(
|
||||
&format!("{}x{}", x, y),
|
||||
Point::new(5, 5),
|
||||
character_style,
|
||||
textstyle,
|
||||
)
|
||||
.draw(&mut display)?;
|
||||
if let Err(e) = app.draw(&mut g13) {
|
||||
eprintln!("{:?}", e);
|
||||
}
|
||||
|
||||
display.render()?;
|
||||
}
|
||||
g13.render()?;
|
||||
|
||||
Ok(())
|
||||
let elapsed = Instant::now() - start;
|
||||
if elapsed.as_millis() < 33 {
|
||||
sleep(Duration::from_millis(33) - (elapsed));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user