I would like to pass an extra parameter to an event handler. As of now, event handlers have lv_obj_t and lv_event_t as parameter type. When the event is associated to something using lv_obj_set_event_cb(lv_obg_t, func). I would like my func to pass more than the two previously mentioned parameters. Is that possible ?
v8 should (finally) be pretty much stable. (It was supposed to be stable in February but a number of issues were discovered which required more API changes.)
However, the documentation is not complete yet, so you will have to do quite a bit of reading through the code to figure out how the new APIs work. If you are looking for stability, I would suggest sticking with v7 for now, as the documentation there is largely complete and there aren’t going to be any more changes to it besides bugfixes.
Thanks for the reply. I still have a problem though. Assume I have a custom_type * object, so a pointer to a custom type (structure in my case) called object. I want to pass object by reference to the event handler function but it looks like I can’t. If I check the address of what I get from lv_event_get_data() it is different from the object pointer. Is there a way to solve this ?
Then, inside generate_empty_table() I want to pass the object to an event handler called
Problem is that when I try to get back my original object inside select_event_handler it seems like the object pointer is not pointing anymore to &tav1. The *object in the previous functions ( tavola_impostazioni_create and generate_empty_table ) is pointing towards the right address of tav1. Once the object is given to the select_event_handler with lv_event_sent the object pointer inside select_event_handler is not pointing to the right address anymore.
Let’s say I get back my object pointer in the following way inside select_event_handler:
tavola_impostazioni * get = lv_event_get_data();
Look at the address changes:
tav1 is located at 0x55a83a5ea9c0
tavola_impostazioni_create object pointer at 0x7ffe62149ee8
tavola_impostazioni_create object points to 0x55a83a5ea9c0
generate empty table object pointer at 0x7ffe62149eb8
generate empty table objects points to 0x55a83a5ea9c0
select_event_handler object pointer from lv_event_get_data at address 0x7ffe62149c80
select_event_handler object pointer from lv_event_get_data points to 0x7ffe62149d6c
I hope that was clear enough for you to understand.
Ok, I solved the issue but not using what you suggested. Instead I used lv_obj_set_user_data() to set the user data to the object and then lv_obj_get_user_data(object) to get the user data back. So the previous way it creates a new instance of the user data being assigned to the object while this one does not. More specifically, I think is the function used to get the object back. To sum up:
lv_event_get_data() -> creates a new instance.
lv_obj_get_user_data(object) -> returns you the original pointer.