Create event for buttons in container

I have some buttons that into container.
I want to create an event that will sharr beween all of bytton in that container.
For example when click of those button do…
I know how to config an even for each of those buttons.

I tried to config onclick even to containers but when I click on button, nothings happend.
I even bind them to componet . And config an onclick even on component, but still when I click on the buttons nothings happend.

How can I do thay without copy the even for each buttons in that container?

You can do the following: create the buttons into a component and then create the event within the component, this way the event will be valid for all the buttons in the component. Not all event types work within the component, please experiment a bit. Check out the related tutorial here: https://www.youtube.com/watch?v=-jDrjwVE7G8

Thanks, this is very helpful. My question is - if I use the same function for a group of buttons, is there a way to access the properties of the button to find out which button triggered the event? I assume this would be available through the lv_event_t object but I can’t find any documentation on it.

thanks again

You can find out the widget (button in your case) which triggered the event by getting the click event’s ‘target’ object with lv_event_get_target( event ) in the callback function. ( In C code you can even assign an ‘user_data’ which can be requested by lv_event_get_user_data( event ). )

Thank you!

1 Like