-
Notifications
You must be signed in to change notification settings - Fork 74
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
Consider moving boilerplate into its own module/crate? #24
Comments
@embeddedt True, that is a valid concern. I just think we need to focus on showing how to use the library. If we start designing too much the examples, it will be difficult for people to understand what is going on. Do you have an example in C that uses LVGL without threads? I was thinking we could remove this |
None of the example code itself uses threads (as the library is not threaded), however, most of the platform implementations run For nearly all the platforms, Does Rust have a function that returns the number of milliseconds since system startup? If so, we can use that, and not even bother calling
Exactly. I know that the code is really just calling OT: Can you explain why you need to create an arc to call let threaded_ui = Arc::new(Mutex::new(ui));
threaded_ui.lock().unwrap().task_handler(); |
I just updated the one example to remove the An |
That definition of I've installed Rust on my computer so hopefully I can give this a try at some point and see how it compares to using C directly. I just have two more suggestions.
|
I've updated all examples removing the threads. 👍 On the other suggestions, it's complicated...
Thanks for your comments! This helps a lot. 😃 |
In my opinion, the best thing to do here is to make sure that a string literal "just works" (TM) without needing any extra wrapper around it in the user's code. |
Yes, that is what I meant. Rust "string literals" are static strings, so to append a nul byte at the end I need to, internally, have a sort of dynamic array and copy the static string data from Rust in there and add a |
I see. This is an unfortunate limitation, because it makes passing strings to C quite inefficient. It would be nice if the Rust compiler had a flag that would make it generate the strings with |
Yeah, that doesn't exist. Best thing is to let users pass a instance of |
Now see a better way to deal with this. If the users the the lib enable fn set_text_cstr(&mut self, text: impl AsRef<cstr_core::CStr>) -> Result<(), Error> {
// Calls LVGL FFI
}
#[cfg(feature = "alloc")]
fn set_text(&mut self, text: impl AsRef<str>) -> Result<(), Error> {
// Converts to a CStr here to have the `\0` at the end
self.set_text_cstr(&CString::new(text.as_ref())?.as_c_str())
} If the loading_lbl.set_text("Loading...")?;
let text = String::new("Click me!");
button_lbl.set_text(text)?; |
I'm reading the examples to gain an understanding of how this works and I notice that the boilerplate for calling
lv_task_handler
andlv_tick_inc
is duplicated across many of the examples. It might be worth moving this to a common crate where it can be reused.https://github.com/rafaelcaricio/lvgl-rs/blob/b85226aadac7b9eeed6bebcb34f2008ea803eaa4/examples/gauge.rs#L60-L107
The text was updated successfully, but these errors were encountered: