From 256341cd5e744ff8a10aa9e5f753db4786629d53 Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Sat, 28 Dec 2024 21:23:29 +0100 Subject: [PATCH] Add embedded, gui, and simulator in same repo --- {.cargo => embedded/.cargo}/config.toml | 0 Cargo.toml => embedded/Cargo.toml | 0 README.md => embedded/README.md | 0 build.rs => embedded/build.rs | 0 memory.x => embedded/memory.x | 0 .../rust-toolchain.toml | 0 {src => embedded/src}/main.rs | 0 gui | 1 + simulator/Cargo.toml | 12 ++++++ simulator/src/main.rs | 43 +++++++++++++++++++ 10 files changed, 56 insertions(+) rename {.cargo => embedded/.cargo}/config.toml (100%) rename Cargo.toml => embedded/Cargo.toml (100%) rename README.md => embedded/README.md (100%) rename build.rs => embedded/build.rs (100%) rename memory.x => embedded/memory.x (100%) rename rust-toolchain.toml => embedded/rust-toolchain.toml (100%) rename {src => embedded/src}/main.rs (100%) create mode 160000 gui create mode 100644 simulator/Cargo.toml create mode 100644 simulator/src/main.rs diff --git a/.cargo/config.toml b/embedded/.cargo/config.toml similarity index 100% rename from .cargo/config.toml rename to embedded/.cargo/config.toml diff --git a/Cargo.toml b/embedded/Cargo.toml similarity index 100% rename from Cargo.toml rename to embedded/Cargo.toml diff --git a/README.md b/embedded/README.md similarity index 100% rename from README.md rename to embedded/README.md diff --git a/build.rs b/embedded/build.rs similarity index 100% rename from build.rs rename to embedded/build.rs diff --git a/memory.x b/embedded/memory.x similarity index 100% rename from memory.x rename to embedded/memory.x diff --git a/rust-toolchain.toml b/embedded/rust-toolchain.toml similarity index 100% rename from rust-toolchain.toml rename to embedded/rust-toolchain.toml diff --git a/src/main.rs b/embedded/src/main.rs similarity index 100% rename from src/main.rs rename to embedded/src/main.rs diff --git a/gui b/gui new file mode 160000 index 0000000..12afc17 --- /dev/null +++ b/gui @@ -0,0 +1 @@ +Subproject commit 12afc17f90756988b9011240e6884fa0e3fb48ef diff --git a/simulator/Cargo.toml b/simulator/Cargo.toml new file mode 100644 index 0000000..a08949e --- /dev/null +++ b/simulator/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "gui-test" +version = "0.1.0" +edition = "2021" + +[dependencies] +embedded-graphics = "0.8.1" +embedded-graphics-simulator = "0.7.0" +embedded-layout = "0.4.1" +heapless = "0.8.0" +profont = "0.7.0" +gui = { path = "../gui/" } diff --git a/simulator/src/main.rs b/simulator/src/main.rs new file mode 100644 index 0000000..ae2c4d3 --- /dev/null +++ b/simulator/src/main.rs @@ -0,0 +1,43 @@ +use embedded_graphics::{geometry::Size, pixelcolor::Rgb565}; +use embedded_graphics_simulator::{ + sdl2::Keycode, OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, +}; + +use gui::*; + +fn main() -> Result<(), core::convert::Infallible> { + let display = SimulatorDisplay::::new(Size::new(240, 320)); + + let output_settings = OutputSettingsBuilder::new().scale(1).build(); + let mut window = Window::new("Hello World", &output_settings); + + let mut gui = Gui::new(display); + + 'running: loop { + gui.draw()?; + window.update(gui.display_ref()); + + for event in window.events() { + match event { + SimulatorEvent::Quit => break 'running, + SimulatorEvent::KeyDown { keycode, .. } => { + let action: GuiAction = match keycode { + Keycode::Left => GuiAction::Left, + Keycode::Right => GuiAction::Right, + Keycode::Up => GuiAction::Up, + Keycode::Down => GuiAction::Down, + Keycode::Return => GuiAction::Select, + Keycode::Backspace => GuiAction::Back, + _ => continue, + }; + + gui = gui.action(action); + gui.fill_black()?; + } + _ => {} + } + } + } + + Ok(()) +}