forked from pinealservo/blue_pill_ui
Integrate embedded-graphics ui with simulator
This commit is contained in:
10
ui-sim/Cargo.toml
Normal file
10
ui-sim/Cargo.toml
Normal 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
43
ui-sim/src/main.rs
Normal 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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user