diff --git a/examples/demo.rs b/examples/demo.rs index c432d6e..6b2533b 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -12,43 +12,6 @@ use lvgl_sys; use std::sync::{mpsc, Arc, Mutex}; use std::thread::sleep; use std::time::Duration; -// -// struct MyApp { -// time: Label, -// bt_label: Label, -// } -// -// impl MyApp { -// fn initialize(screen: &Obj) -> Result { -// let mut screen_style = Style::default(); -// screen_style.set_bg_color(State::DEFAULT, Color::from_rgb((0, 0, 0))); -// screen_style.set_radius(State::DEFAULT, 0); -// -// let mut style_time = Style::default(); -// style_time.set_text_color(State::DEFAULT, Color::from_rgb((255, 255, 255))); -// -// let time = screen.create_label()?; -// time.set_align(&screen, Align::Center, 0, 0)?; -// time.set_text(CString::new("20:46").unwrap().as_c_str())?; -// time.set_width(240)?; -// time.set_height(240)?; -// -// let bt = screen.create_label()?; -// bt.set_height(80)?; -// bt.set_recolor(true)?; -// bt.set_height(80)?; -// bt.set_recolor(true)?; -// bt.set_text(CString::new("#5794f2 \u{F293}#").unwrap().as_c_str())?; -// bt.set_label_align(LabelAlign::Left)?; -// bt.set_align(&screen, Align::InTopLeft, 0, 0)?; -// -// // attach styles -// screen.add_style(Part::Main, screen_style)?; -// time.add_style(Part::Main, style_time)?; -// -// Ok(MyApp { time, bt_label: bt }) -// } -// } fn main() -> Result<(), LvError> { let display: SimulatorDisplay = SimulatorDisplay::new(Size::new( @@ -100,8 +63,9 @@ fn main() -> Result<(), LvError> { let mut t: heapless::String = heapless::String::from("test"); t.push('\0').unwrap(); + CStr::from_bytes_with_nul_unchecked(); set_text(CStr::from_bytes_with_nul(t.as_bytes()).unwrap()).unwrap(); - set_text(CStr::from_bytes_with_nul(("test\0").as_bytes()).unwrap()).unwrap(); + set_text(cstr_core::CStr::from_bytes_with_nul("test\0".as_bytes()).unwrap()).unwrap(); set_text(cstr_core::CString::new("test").unwrap().as_c_str()).unwrap(); let mut power = Label::new(&mut screen)?; diff --git a/lvgl-codegen/src/lib.rs b/lvgl-codegen/src/lib.rs index 2e51afd..73917f1 100644 --- a/lvgl-codegen/src/lib.rs +++ b/lvgl-codegen/src/lib.rs @@ -99,6 +99,7 @@ impl Rusty for LvFunc { // generate constructor if new_name.as_str().eq("create") { return Ok(quote! { + pub fn new(parent: &mut C) -> crate::LvResult where C: crate::NativeObject, @@ -113,6 +114,7 @@ impl Rusty for LvFunc { } } } + }); } diff --git a/lvgl/Cargo.toml b/lvgl/Cargo.toml index 45d851c..bd29e1b 100644 --- a/lvgl/Cargo.toml +++ b/lvgl/Cargo.toml @@ -15,7 +15,7 @@ build = "build.rs" lvgl-sys = { version = "0.3.3", path = "../lvgl-sys" } cty = "0.2.1" embedded-graphics = "0.6.2" -cstr_core = { version = "0.2.0", default-features = false, features = ["alloc"] } +cstr_core = { version = "0.2.0" } bitflags = "1.2.1" heapless = "0.5.5" typenum = "1.12.0" diff --git a/lvgl/src/ui.rs b/lvgl/src/ui.rs index cb89bf1..7902c1b 100644 --- a/lvgl/src/ui.rs +++ b/lvgl/src/ui.rs @@ -62,14 +62,13 @@ where phantom: PhantomData, }); + let refresh_buffer1 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE]; + let refresh_buffer2 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE]; + + let mut disp_buf = MaybeUninit::::uninit(); + unsafe { - // Create a display buffer for LittlevGL // Initialize the display buffer - let refresh_buffer1 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE]; - let refresh_buffer2 = [Color::from_rgb((0, 0, 0)).raw; BUF_SIZE]; - - let mut disp_buf = MaybeUninit::::uninit(); - lvgl_sys::lv_disp_buf_init( disp_buf.as_mut_ptr(), Box::into_raw(Box::new(refresh_buffer1)?) as *mut cty::c_void, @@ -87,8 +86,6 @@ where disp_drv.buffer = Box::into_raw(disp_buf); // Set your driver function disp_drv.flush_cb = Some(display_callback_wrapper::); - // TODO: DrawHandler type here - // Safety: `user_data` is set to NULL in C code. disp_drv.user_data = &mut self.display_data as *mut _ as *mut cty::c_void; lvgl_sys::lv_disp_drv_register( &mut ManuallyDrop::take(&mut disp_drv) as *mut lvgl_sys::lv_disp_drv_t