Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_text interface/trait for Label and Textarea widgets #188

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add initial implementation of Textarea widget
C47D committed Jan 9, 2025
commit 65d117384544af7fde8adea8b5304e0928a809f3
2 changes: 2 additions & 0 deletions lvgl/src/widgets/mod.rs
Original file line number Diff line number Diff line change
@@ -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::*;
29 changes: 29 additions & 0 deletions lvgl/src/widgets/textarea.rs
Original file line number Diff line number Diff line change
@@ -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<S: AsRef<str>> From<S> 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()
}
}