Button callbacks #5

Closed
opened 2020-05-15 04:04:16 +00:00 by justinmoon · 9 comments
justinmoon commented 2020-05-15 04:04:16 +00:00 (Migrated from github.com)

How can I define a button "on-click" callback?

I'm trying to add a button example and I'm stuck trying to type the callback to lvgl_sys::lvgl_obj_set_event_cb

How can I define a button "on-click" callback? I'm trying to add a button example and [I'm stuck trying to type the callback to `lvgl_sys::lvgl_obj_set_event_cb`](https://github.com/justinmoon/lvgl-rs/blob/50105eb3dcb2cbcb8dfb4cf0427a199d861aa058/examples/button/src/main.rs#L42)
justinmoon commented 2020-05-15 04:45:22 +00:00 (Migrated from github.com)

It seems like lvgl_sys wants the callback to be an unsafe extern "C" function, which doesn't really make sense if I'm providing this callback from Rust ...

It seems like `lvgl_sys` wants the callback to be an `unsafe extern "C"` function, which doesn't really make sense if I'm providing this callback from Rust ...
rafaelcaricio commented 2020-05-15 10:51:25 +00:00 (Migrated from github.com)

Hi @justinmoon,

It is flattering that you have interest in using lvgl-rs. I just wanted to tell you that this project is in the very early stages of development. I would really appreciate help of others, like you, to push this project forward. Most things are still missing and I'm still pondering about how to handle the global state dependency in lvgl library rely.

Hi @justinmoon, It is flattering that you have interest in using lvgl-rs. I just wanted to tell you that this project is in the very early stages of development. I would really appreciate help of others, like you, to push this project forward. Most things are still missing and I'm still pondering about how to handle the global state dependency in lvgl library rely.
justinmoon commented 2020-05-15 19:52:04 +00:00 (Migrated from github.com)

No problem. I'll try to help out wherever I can.

No problem. I'll try to help out wherever I can.
rafaelcaricio commented 2020-05-15 21:06:30 +00:00 (Migrated from github.com)

In general, I'm trying to follow the recommendations from those articles:

In general, I'm trying to follow the recommendations from those articles: - http://adventures.michaelfbryan.com/posts/how-not-to-riir/ - https://kornel.ski/rust-sys-crate
justinmoon commented 2020-05-15 21:19:59 +00:00 (Migrated from github.com)

Thanks for sharing.

I'm trying to figure out how to get these event callbacks working. This post seems to explain roughly what is needed, but still working on it

Thanks for sharing. I'm trying to figure out how to get these event callbacks working. [This post](https://users.rust-lang.org/t/callback-based-c-ffi/26583/5) seems to explain roughly what is needed, but still working on it
justinmoon commented 2020-05-15 22:08:46 +00:00 (Migrated from github.com)

On a related note, how were you able to get a button to look like this?
image

Mine look like this
image

Might help if you could add whatever code produced your screenshot as an example.

On a related note, how were you able to get a button to look like this? ![image](https://user-images.githubusercontent.com/4335621/82100064-75ae2d80-96ce-11ea-8368-63404e453bf9.png) Mine look like this ![image](https://user-images.githubusercontent.com/4335621/82100169-b3ab5180-96ce-11ea-8711-665b46017fba.png) Might help if you could add whatever code produced your screenshot as an example.
rafaelcaricio commented 2020-05-27 20:04:09 +00:00 (Migrated from github.com)

@justinmoon that screenshot was in an earlier version of the demo app, 7bf1ac0cae/examples/demo/src/main.rs I was using SDL directly.

@justinmoon that screenshot was in an earlier version of the demo app, https://github.com/rafaelcaricio/lvgl-rs/blob/7bf1ac0cae3b1867b4687efaf1ccbd9e321df54b/examples/demo/src/main.rs I was using SDL directly.
rafaelcaricio commented 2020-05-31 17:28:24 +00:00 (Migrated from github.com)

Hey @justinmoon , I just implemented a way to add event callbacks. So you can do things when buttons are clicked, hovered, etc. Please look the example:

let mut button = Button::new(&mut screen);
button.on_event(|this, event| {
    if let lvgl::Event::Clicked = event {
        println!("Clicked!");
    }
});

https://github.com/rafaelcaricio/lvgl-rs/blob/master/examples/bar.rs#L48-L52

Hey @justinmoon , I just implemented a way to add event callbacks. So you can do things when buttons are clicked, hovered, etc. Please look the example: ```rust let mut button = Button::new(&mut screen); button.on_event(|this, event| { if let lvgl::Event::Clicked = event { println!("Clicked!"); } }); ``` https://github.com/rafaelcaricio/lvgl-rs/blob/master/examples/bar.rs#L48-L52
rafaelcaricio commented 2020-05-31 17:29:36 +00:00 (Migrated from github.com)

I will close this ticket now, as this is now supported. If you have other questions. Please open other issue.

I will close this ticket now, as this is now supported. If you have other questions. Please open other issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: rafaelcaricio/lvgl-rs#5
No description provided.