diff --git a/lvgl/src/widgets/label.rs b/lvgl/src/widgets/label.rs index 691ffb8d..5235f864 100644 --- a/lvgl/src/widgets/label.rs +++ b/lvgl/src/widgets/label.rs @@ -1,5 +1,6 @@ use crate::widgets::Label; use crate::{LabelLongMode, NativeObject}; +use cstr_core::CStr; #[cfg(feature = "alloc")] mod alloc_imp { @@ -41,4 +42,10 @@ impl Label<'_> { pub fn get_long_mode(&self) -> u8 { unsafe { lvgl_sys::lv_label_get_long_mode(self.raw().as_ref()) } } + + pub fn get_text(&self) -> &'static str { + let char_ptr = unsafe { lvgl_sys::lv_label_get_text(self.raw().as_ref()) }; + let c_str = unsafe { CStr::from_ptr(char_ptr) }; + c_str.to_str().unwrap_or_default() + } } diff --git a/lvgl/src/widgets/mod.rs b/lvgl/src/widgets/mod.rs index a83f7262..7648cbcb 100644 --- a/lvgl/src/widgets/mod.rs +++ b/lvgl/src/widgets/mod.rs @@ -12,6 +12,7 @@ mod label; mod meter; mod slider; mod table; +mod textarea; include!(concat!(env!("OUT_DIR"), "/generated.rs")); @@ -23,3 +24,4 @@ pub use label::*; pub use meter::*; pub use slider::*; pub use table::*; +pub use textarea::*; diff --git a/lvgl/src/widgets/textarea.rs b/lvgl/src/widgets/textarea.rs new file mode 100644 index 00000000..1a967b64 --- /dev/null +++ b/lvgl/src/widgets/textarea.rs @@ -0,0 +1,29 @@ +use crate::widgets::Textarea; +use crate::NativeObject; +use cstr_core::CStr; + +#[cfg(feature = "alloc")] +mod alloc_imp { + use crate::widgets::Textarea; + //use crate::LvError; + use cstr_core::CString; + //use core::convert::TryFrom; + + impl> From for Textarea<'_> { + fn from(text: S) -> Self { + // text.try_into().unwrap() + let text_cstr = CString::new(text.as_ref()).unwrap(); + let mut ta = Textarea::new().unwrap(); + ta.set_text(text_cstr.as_c_str()).unwrap(); + ta + } + } +} + +impl Textarea<'_> { + pub fn get_text(&self) -> &'static str { + let char_ptr = unsafe { lvgl_sys::lv_textarea_get_text(self.raw().as_ref()) }; + let c_str = unsafe { CStr::from_ptr(char_ptr) }; + c_str.to_str().unwrap_or_default() + } +}