diff --git a/lvgl/src/lv_core/style.rs b/lvgl/src/lv_core/style.rs index 46611b8..9995fe2 100644 --- a/lvgl/src/lv_core/style.rs +++ b/lvgl/src/lv_core/style.rs @@ -7,6 +7,7 @@ pub enum Themes { Pretty, } +#[derive(Clone)] pub struct Style { pub(crate) raw: Box, } diff --git a/lvgl/src/mem.rs b/lvgl/src/mem.rs index 0d193d7..669c447 100644 --- a/lvgl/src/mem.rs +++ b/lvgl/src/mem.rs @@ -69,6 +69,12 @@ impl AsMut for Box { } } +impl Clone for Box { + fn clone(&self) -> Self { + unsafe { Self::new(self.0.as_ref().clone()) } + } +} + #[cfg(test)] mod test { use super::*; @@ -136,6 +142,19 @@ mod test { assert_eq!(initial_mem_info.free_size, final_info.free_size) } + #[test] + fn clone_object_in_lv_mem() { + crate::lvgl_init(); + + let v1 = Box::new(5); + let v2 = v1.clone(); + + // Ensure that the two objects have identical values. + assert_eq!(*v1, *v2); + // They should have different memory addresses, however. + assert_ne!(v1.into_raw() as usize, v2.into_raw() as usize); + } + fn mem_info() -> lvgl_sys::lv_mem_monitor_t { let mut info = lvgl_sys::lv_mem_monitor_t { total_size: 0,