Skip to content

Commit

Permalink
Update LVGL version to 8.3.5 and rework API
Browse files Browse the repository at this point in the history
bump lvgl to 8.3.5

begin fixing for 8.x

simplify style generation

rework display buffer

make lvgl_alloc build

fix tests

fix input devices
  • Loading branch information
nia-e committed Mar 6, 2023
1 parent 0cb1ab4 commit 86dd9ae
Show file tree
Hide file tree
Showing 31 changed files with 1,823 additions and 2,692 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Cargo.lock

# These are backup files generated by rustfmt
**/*.rs.bk
.vscode/
.idea/
examples/demo/target/
lvgl-sys/target/
Expand Down
14 changes: 9 additions & 5 deletions examples/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ use embedded_graphics::prelude::*;
use embedded_graphics_simulator::{OutputSettingsBuilder, SimulatorDisplay, Window};
use lvgl;
use lvgl::widgets::Label;
use lvgl::{Display, DrawBuffer, HOR_RES_MAX, VER_RES_MAX};
use lvgl::{Display, DrawBuffer};
use std::cell::RefCell;

type ColorSpace = Rgb565;

#[allow(unused_mut)]
#[allow(unused_variables)]
fn main() {
const HOR_RES: u32 = 240;
const VER_RES: u32 = 240;

let embedded_graphics_display: SimulatorDisplay<ColorSpace> =
SimulatorDisplay::new(Size::new(HOR_RES_MAX as u32, VER_RES_MAX as u32));
SimulatorDisplay::new(Size::new(HOR_RES, VER_RES));

let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("App Example", &output_settings);
Expand All @@ -22,12 +25,13 @@ fn main() {
// LVGL usage
lvgl::init();

let buffer = DrawBuffer::<{ (HOR_RES_MAX * VER_RES_MAX) as usize }>::new();
let buffer = DrawBuffer::<{ (HOR_RES * VER_RES) as usize }>::new();

let display = Display::register(&buffer, |refresh| {
let display = Display::register(buffer, HOR_RES, VER_RES, |refresh| {
shared_native_display
.borrow_mut()
.draw_iter(refresh.as_pixels()).unwrap();
.draw_iter(refresh.as_pixels())
.unwrap();
})
.unwrap();

Expand Down
63 changes: 21 additions & 42 deletions examples/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ use embedded_graphics_simulator::{
};
use lvgl;
use lvgl::style::Style;
use lvgl::widgets::{Arc, Label, LabelAlign};
use lvgl::{
Align, Color, Display, DrawBuffer, LvError, Part, State, Widget, HOR_RES_MAX,
VER_RES_MAX,
};
use lvgl::widgets::{Arc, Label};
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
use lvgl_sys;
use std::cell::RefCell;
use std::thread;
use std::time::Duration;

fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
Expand All @@ -34,67 +29,50 @@ fn mem_info() -> lvgl_sys::lv_mem_monitor_t {
}

fn main() -> Result<(), LvError> {
println!("meminfo init: {:?}", mem_info());
run_arc_demo()?;
println!("meminfo end: {:?}", mem_info());
Ok(())
}
const HOR_RES: u32 = 240;
const VER_RES: u32 = 240;

fn run_arc_demo() -> Result<(), LvError> {
lvgl::init();
let sim_display: SimulatorDisplay<Rgb565> =
SimulatorDisplay::new(Size::new(HOR_RES_MAX, VER_RES_MAX));
println!("meminfo init: {:?}", mem_info());
let mut sim_display: SimulatorDisplay<Rgb565> =
SimulatorDisplay::new(Size::new(HOR_RES, VER_RES));

let output_settings = OutputSettingsBuilder::new().scale(2).build();
let output_settings = OutputSettingsBuilder::new().scale(1).build();
let mut window = Window::new("Arc Example", &output_settings);

let shared_native_display = RefCell::new(sim_display);

let buffer = DrawBuffer::<{ (HOR_RES_MAX * VER_RES_MAX) as usize }>::new();
let buffer = DrawBuffer::<{ (HOR_RES * VER_RES) as usize }>::new();

let display = Display::register(&buffer, |refresh| {
shared_native_display
.borrow_mut()
.draw_iter(refresh.as_pixels())
.unwrap();
let display = Display::register(buffer, HOR_RES, VER_RES, |refresh| {
sim_display.draw_iter(refresh.as_pixels()).unwrap();
})?;

let mut screen = display.get_scr_act()?;

let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((255, 255, 255)));
screen_style.set_radius(State::DEFAULT, 0);
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
screen_style.set_radius(0);
screen.add_style(Part::Main, &mut screen_style)?;

// Create the arc object
let mut arc = Arc::create(&mut screen, None)?;
let mut arc = Arc::create(&mut screen)?;
arc.set_size(150, 150)?;
arc.set_align(&mut screen, Align::Center, 0, 10)?;
arc.set_align(Align::Center, 0, 10)?;
arc.set_start_angle(135)?;
arc.set_end_angle(135)?;

let mut loading_lbl = Label::create(&mut screen, None)?;
let mut loading_lbl = Label::create(&mut screen)?;
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str())?;
loading_lbl.set_align(&mut arc, Align::OutTopMid, 0, -10)?;
loading_lbl.set_label_align(LabelAlign::Center)?;
loading_lbl.set_align(Align::OutTopMid, 0, 0)?;
//loading_lbl.set_label_align(LabelAlign::Center)?;

let mut loading_style = Style::default();
loading_style.set_text_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, &mut loading_style)?;

let mut angle = 0;
let mut forward = true;
let mut i = 0;

// LVGL timer thread
thread::spawn(|| {
let interval = Duration::from_millis(5);
loop {
thread::sleep(interval);
lvgl::tick_inc(interval);
}
});

'running: loop {
if i > 270 {
forward = if forward { false } else { true };
Expand All @@ -106,7 +84,7 @@ fn run_arc_demo() -> Result<(), LvError> {
i += 1;

lvgl::task_handler();
window.update(&shared_native_display.borrow());
window.update(&sim_display);

for event in window.events() {
match event {
Expand All @@ -116,6 +94,7 @@ fn run_arc_demo() -> Result<(), LvError> {
}
lvgl::tick_inc(Duration::from_millis(15));
}
println!("meminfo end: {:?}", mem_info());

Ok(())
}
39 changes: 19 additions & 20 deletions examples/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@ use embedded_graphics_simulator::{
};
use lvgl;
use lvgl::style::Style;
use lvgl::widgets::{Bar, Label, LabelAlign};
use lvgl::{
Align, Animation, Color, Display, DrawBuffer, Event, LvError, Part, State, Widget, HOR_RES_MAX,
VER_RES_MAX,
};
use lvgl::widgets::{Bar, Label};
use lvgl::{Align, Animation, Color, Display, DrawBuffer, Event, LvError, Part, Widget};
use std::cell::RefCell;
use std::time::Duration;

fn main() -> Result<(), LvError> {
const HOR_RES: u32 = 240;
const VER_RES: u32 = 240;

lvgl::init();
let sim_display: SimulatorDisplay<Rgb565> =
SimulatorDisplay::new(Size::new(HOR_RES_MAX, VER_RES_MAX));
let sim_display: SimulatorDisplay<Rgb565> = SimulatorDisplay::new(Size::new(HOR_RES, VER_RES));

let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("Bar Example", &output_settings);

let shared_native_display = RefCell::new(sim_display);

let buffer = DrawBuffer::<{ (HOR_RES_MAX * VER_RES_MAX) as usize }>::new();
let buffer = DrawBuffer::<{ (HOR_RES * VER_RES) as usize }>::new();

let display = Display::register(&buffer, |refresh| {
let display = Display::register(buffer, HOR_RES, VER_RES, |refresh| {
shared_native_display
.borrow_mut()
.draw_iter(refresh.as_pixels())
Expand All @@ -36,31 +35,31 @@ fn main() -> Result<(), LvError> {
let mut screen = display.get_scr_act()?;

let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((255, 255, 255)));
screen_style.set_radius(State::DEFAULT, 0);
screen_style.set_bg_color(Color::from_rgb((255, 255, 255)));
screen_style.set_radius(0);
screen.add_style(Part::Main, &mut screen_style)?;

// Create the bar object
let mut bar = Bar::create(&mut screen, None)?;
let mut bar = Bar::create(&mut screen)?;
bar.set_size(175, 20)?;
bar.set_align(&mut screen, Align::Center, 0, 10)?;
bar.set_align(Align::Center, 0, 10)?;
bar.set_range(0, 100)?;
bar.on_event(|_b, _e| {
println!("Completed!");
})?;

// // Set the indicator style for the bar object
// Set the indicator style for the bar object
let mut ind_style = Style::default();
ind_style.set_bg_color(State::DEFAULT, Color::from_rgb((100, 245, 100)));
bar.add_style(Part::All, &mut ind_style)?;
ind_style.set_bg_color(Color::from_rgb((100, 245, 100)));
bar.add_style(Part::Any, &mut ind_style)?;

let mut loading_lbl = Label::create(&mut screen, None)?;
let mut loading_lbl = Label::create(&mut screen)?;
loading_lbl.set_text(CString::new("Loading...").unwrap().as_c_str())?;
loading_lbl.set_align(&mut bar, Align::OutTopMid, 0, -10)?;
loading_lbl.set_label_align(LabelAlign::Center)?;
loading_lbl.set_align(Align::OutTopMid, 0, 0)?;
//loading_lbl.set_label_align(LabelAlign::Center)?;

let mut loading_style = Style::default();
loading_style.set_text_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
loading_style.set_text_color(Color::from_rgb((0, 0, 0)));
loading_lbl.add_style(Part::Main, &mut loading_style)?;

let mut i = 0;
Expand Down
38 changes: 16 additions & 22 deletions examples/button_click.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,25 @@ use lvgl::input_device::{
};
use lvgl::style::Style;
use lvgl::widgets::{Btn, Label};
use lvgl::{
Align, Color, Display, DrawBuffer, LvError, Part, State, Widget, HOR_RES_MAX, VER_RES_MAX,
};
use std::cell::RefCell;
use lvgl::{Align, Color, Display, DrawBuffer, LvError, Part, Widget};
use std::time::Duration;

#[allow(unused_assignments)]
fn main() -> Result<(), LvError> {
const HOR_RES: u32 = 240;
const VER_RES: u32 = 240;

lvgl::init();
let sim_display: SimulatorDisplay<Rgb565> =
SimulatorDisplay::new(Size::new(HOR_RES_MAX, VER_RES_MAX));
let mut sim_display: SimulatorDisplay<Rgb565> =
SimulatorDisplay::new(Size::new(HOR_RES, VER_RES));

let output_settings = OutputSettingsBuilder::new().scale(2).build();
let mut window = Window::new("Button Example", &output_settings);

let shared_native_display = RefCell::new(sim_display);
let buffer = DrawBuffer::<{ (HOR_RES * VER_RES) as usize }>::new();

let buffer = DrawBuffer::<{ (HOR_RES_MAX * VER_RES_MAX) as usize }>::new();

let display = Display::register(&buffer, |refresh| {
shared_native_display
.borrow_mut()
.draw_iter(refresh.as_pixels())
.unwrap();
let display = Display::register(buffer, HOR_RES, VER_RES, |refresh| {
sim_display.draw_iter(refresh.as_pixels()).unwrap();
})?;

// Define the initial state of your input
Expand All @@ -49,17 +44,17 @@ fn main() -> Result<(), LvError> {
let mut screen = display.get_scr_act()?;

let mut screen_style = Style::default();
screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((0, 0, 0)));
screen_style.set_bg_color(Color::from_rgb((0, 0, 0)));
screen.add_style(Part::Main, &mut screen_style)?;
// Create the button
let mut button = Btn::create(&mut screen, None)?;
button.set_align(&mut screen, Align::InLeftMid, 30, 0)?;
let mut button = Btn::create(&mut screen)?;
button.set_align(Align::LeftMid, 30, 0)?;
button.set_size(180, 80)?;
let mut btn_lbl = Label::create(&mut button, None)?;
let mut btn_lbl = Label::create(&mut button)?;
btn_lbl.set_text(CString::new("Click me!").unwrap().as_c_str())?;

let mut btn_state = false;
button.on_event(|mut btn, event| {
button.on_event(|_btn, event| {
println!("Button received event: {:?}", event);
if let lvgl::Event::Clicked = event {
if btn_state {
Expand All @@ -70,14 +65,14 @@ fn main() -> Result<(), LvError> {
btn_lbl.set_text(nt.as_c_str()).unwrap();
}
btn_state = !btn_state;
btn.toggle().unwrap();
//btn.toggle().unwrap();
}
})?;

let mut latest_touch_point = Point::new(0, 0);
'running: loop {
lvgl::task_handler();
window.update(&shared_native_display.borrow());
window.update(&sim_display);

let mut events = window.events().peekable();

Expand All @@ -102,7 +97,6 @@ fn main() -> Result<(), LvError> {
_ => {}
}
}

lvgl::tick_inc(Duration::from_millis(15));
}

Expand Down
Loading

0 comments on commit 86dd9ae

Please sign in to comment.