Integrate embedded-graphics ui with simulator

This commit is contained in:
2022-03-07 02:37:32 -07:00
parent 9fdd9a4482
commit 7088f63c25
15 changed files with 1455 additions and 75 deletions

10
ui-sim/Cargo.toml Normal file
View File

@@ -0,0 +1,10 @@
[package]
authors = ["The author"]
name = "ui-sim"
version = "0.1.0"
edition = "2021"
[dependencies]
ui = { path = "../ui" }
embedded-graphics = "0.7.1"
embedded-graphics-simulator = "0.3.0"

43
ui-sim/src/main.rs Normal file
View File

@@ -0,0 +1,43 @@
use embedded_graphics::{pixelcolor::BinaryColor, prelude::*};
use embedded_graphics_simulator::{
BinaryColorTheme, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window,
};
use std::thread;
use std::time::Duration;
use ui::{HelloDisplay, HelloEvent};
const DISPLAY_W: i32 = 128;
const DISPLAY_H: i32 = 64;
fn main() {
let mut display: SimulatorDisplay<BinaryColor> =
SimulatorDisplay::new(Size::new(DISPLAY_W as u32, DISPLAY_H as u32));
let output_settings = OutputSettingsBuilder::new()
.theme(BinaryColorTheme::OledBlue)
.build();
let mut window = Window::new("Example", &output_settings);
let mut hello: HelloDisplay<DISPLAY_W, DISPLAY_H> = HelloDisplay::new();
'running: loop {
hello.draw(&mut display).unwrap();
window.update(&display);
hello.event(HelloEvent::Tick);
for event in window.events() {
match event {
SimulatorEvent::MouseButtonUp { .. } => {
println!("Click event");
hello.event(HelloEvent::Button);
}
SimulatorEvent::MouseWheel { scroll_delta, .. } => {
hello.event(HelloEvent::Knob(scroll_delta.y));
}
SimulatorEvent::Quit => break 'running,
_ => {}
}
}
thread::sleep(Duration::from_millis(30));
}
}