From 266ccdba031006ba0778e877eb0907e1aecfec7c Mon Sep 17 00:00:00 2001 From: Rafael Caricio Date: Fri, 19 Jun 2020 19:43:14 +0200 Subject: [PATCH] Re-export max resolutions --- examples/Cargo.toml | 4 ++++ examples/arc.rs | 7 ++---- examples/bar.rs | 7 ++---- examples/button_click.rs | 7 ++---- examples/demo.rs | 6 ++--- examples/gauge.rs | 9 +++---- examples/simple.rs | 52 ++++++++++++++++++++++++++++++++++++++++ lvgl/src/lib.rs | 3 +++ 8 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 examples/simple.rs diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 5e116c8..52dd934 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -13,6 +13,10 @@ embedded-graphics-simulator = "0.2.0" heapless = "0.5.5" cstr_core = { version = "0.2.0", features = ["alloc"] } +[[example]] +name = "simple" +path = "simple.rs" + [[example]] name = "demo" path = "demo.rs" diff --git a/examples/arc.rs b/examples/arc.rs index 05523a4..52183ef 100644 --- a/examples/arc.rs +++ b/examples/arc.rs @@ -8,14 +8,11 @@ use lvgl::style::Style; use lvgl::widgets::{Arc, Label, LabelAlign}; use lvgl::{self, Align, Color, Part, State, UI}; use lvgl::{LvError, Widget}; -use lvgl_sys; use std::time::Instant; fn main() -> Result<(), LvError> { - let display: SimulatorDisplay = SimulatorDisplay::new(Size::new( - lvgl_sys::LV_HOR_RES_MAX, - lvgl_sys::LV_VER_RES_MAX, - )); + let display: SimulatorDisplay = + SimulatorDisplay::new(Size::new(lvgl::HOR_RES_MAX, lvgl::VER_RES_MAX)); let output_settings = OutputSettingsBuilder::new().scale(2).build(); let mut window = Window::new("Arc Example", &output_settings); diff --git a/examples/bar.rs b/examples/bar.rs index 6472b74..ea428d5 100644 --- a/examples/bar.rs +++ b/examples/bar.rs @@ -7,14 +7,11 @@ use embedded_graphics_simulator::{ use lvgl::style::Style; use lvgl::widgets::{Bar, Label, LabelAlign}; use lvgl::{self, Align, Animation, Color, Event, LvError, Part, State, Widget, UI}; -use lvgl_sys; use std::time::Instant; fn main() -> Result<(), LvError> { - let display: SimulatorDisplay = SimulatorDisplay::new(Size::new( - lvgl_sys::LV_HOR_RES_MAX, - lvgl_sys::LV_VER_RES_MAX, - )); + let display: SimulatorDisplay = + SimulatorDisplay::new(Size::new(lvgl::HOR_RES_MAX, lvgl::VER_RES_MAX)); let output_settings = OutputSettingsBuilder::new().scale(2).build(); let mut window = Window::new("Bar Example", &output_settings); diff --git a/examples/button_click.rs b/examples/button_click.rs index 58d6980..f6d47ce 100644 --- a/examples/button_click.rs +++ b/examples/button_click.rs @@ -7,14 +7,11 @@ use embedded_graphics_simulator::{ use lvgl::style::Style; use lvgl::widgets::{Btn, Label}; use lvgl::{self, Align, Color, Event, LvError, Part, State, Widget, UI}; -use lvgl_sys; use std::time::Instant; fn main() -> Result<(), LvError> { - let display: SimulatorDisplay = SimulatorDisplay::new(Size::new( - lvgl_sys::LV_HOR_RES_MAX, - lvgl_sys::LV_VER_RES_MAX, - )); + let display: SimulatorDisplay = + SimulatorDisplay::new(Size::new(lvgl::HOR_RES_MAX, lvgl::VER_RES_MAX)); let output_settings = OutputSettingsBuilder::new().scale(2).build(); let mut window = Window::new("Bar Example", &output_settings); diff --git a/examples/demo.rs b/examples/demo.rs index 60a6be5..b236c2b 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -13,10 +13,8 @@ use std::thread::sleep; use std::time::{Duration, Instant}; fn main() -> Result<(), LvError> { - let display: SimulatorDisplay = SimulatorDisplay::new(Size::new( - lvgl_sys::LV_HOR_RES_MAX, - lvgl_sys::LV_VER_RES_MAX, - )); + let display: SimulatorDisplay = + SimulatorDisplay::new(Size::new(lvgl::HOR_RES_MAX, lvgl::VER_RES_MAX)); let output_settings = OutputSettingsBuilder::new().scale(2).build(); let mut window = Window::new("PineTime", &output_settings); diff --git a/examples/gauge.rs b/examples/gauge.rs index 508e58b..ca236d4 100644 --- a/examples/gauge.rs +++ b/examples/gauge.rs @@ -6,14 +6,11 @@ use embedded_graphics_simulator::{ use lvgl::style::{Opacity, Style}; use lvgl::widgets::Gauge; use lvgl::{self, Align, Color, LvError, Part, State, Widget, UI}; -use lvgl_sys; use std::time::Instant; fn main() -> Result<(), LvError> { - let display: SimulatorDisplay = SimulatorDisplay::new(Size::new( - lvgl_sys::LV_HOR_RES_MAX, - lvgl_sys::LV_VER_RES_MAX, - )); + let display: SimulatorDisplay = + SimulatorDisplay::new(Size::new(lvgl::HOR_RES_MAX, lvgl::VER_RES_MAX)); let output_settings = OutputSettingsBuilder::new().scale(2).build(); let mut window = Window::new("Gauge Example", &output_settings); @@ -36,7 +33,7 @@ fn main() -> Result<(), LvError> { gauge_style.set_radius(State::DEFAULT, 5); gauge_style.set_bg_opa(State::DEFAULT, Opacity::OPA_COVER); gauge_style.set_bg_color(State::DEFAULT, Color::from_rgb((192, 192, 192))); - // Set some paddings + // Set some padding's gauge_style.set_pad_inner(State::DEFAULT, 20); gauge_style.set_pad_top(State::DEFAULT, 20); gauge_style.set_pad_left(State::DEFAULT, 5); diff --git a/examples/simple.rs b/examples/simple.rs new file mode 100644 index 0000000..1a05bd0 --- /dev/null +++ b/examples/simple.rs @@ -0,0 +1,52 @@ +use embedded_graphics::pixelcolor::Rgb565; +use embedded_graphics::prelude::*; +use embedded_graphics_simulator::{ + OutputSettingsBuilder, SimulatorDisplay, SimulatorEvent, Window, +}; +use lvgl::widgets::Keyboard; +use lvgl::LvError; +use lvgl::UI; +use std::time::Instant; + +fn main() -> Result<(), LvError> { + let display: SimulatorDisplay = + SimulatorDisplay::new(Size::new(lvgl::HOR_RES_MAX, lvgl::VER_RES_MAX)); + + let output_settings = OutputSettingsBuilder::new().scale(2).build(); + let mut window = Window::new("Simple Example", &output_settings); + + // Initialize LVGL + let mut ui = UI::init()?; + + // Register your display + ui.disp_drv_register(display)?; + + // Get the active screen + let mut screen = ui.scr_act()?; + + // Create a Keyboard widget on the screen + let _ = Keyboard::new(&mut screen)?; + + let mut loop_started = Instant::now(); + 'running: loop { + // Tell LVGL to process UI related tasks + ui.task_handler(); + + // Update your window with the latest display image + window.update(ui.get_display_ref().unwrap()); + + for event in window.events() { + match event { + SimulatorEvent::Quit => break 'running, + _ => {} + } + } + + // Tell LVGL how much time has past since last loop + ui.tick_inc(loop_started.elapsed()); + + loop_started = Instant::now(); + } + + Ok(()) +} diff --git a/lvgl/src/lib.rs b/lvgl/src/lib.rs index 8042594..adb763c 100644 --- a/lvgl/src/lib.rs +++ b/lvgl/src/lib.rs @@ -13,3 +13,6 @@ pub mod widgets; pub use lv_core::*; pub use support::*; pub use ui::*; + +pub const HOR_RES_MAX: u32 = lvgl_sys::LV_HOR_RES_MAX; +pub const VER_RES_MAX: u32 = lvgl_sys::LV_VER_RES_MAX;