docs(events): add explanation about lv_event_get_target_obj warning and tips (#8996)

This commit is contained in:
André Costa
2025-10-06 09:36:26 +02:00
committed by GitHub
parent 591e1583f5
commit c91452d7df
@@ -245,14 +245,23 @@ Fields of lv_event_t
********************
:cpp:type:`lv_event_t` is the only parameter passed to the event callback and it
contains all data about the event. The following values can be gotten from it:
contains all data about the event. The following values can be retrieved from it:
- :cpp:expr:`lv_event_get_code(e)`: get the event code
- :cpp:expr:`lv_event_get_current_target(e)`: get Widget to which an event was sent. I.e. the Widget whose event handler is being called.
- :cpp:expr:`lv_event_get_target(e)`: get Widget that originally triggered the event (different from :cpp:func:`lv_event_get_target` if :ref:`event bubbling <event_bubbling>` is enabled)
- :cpp:expr:`lv_event_get_target(e)`: get the Widget, Display or Indev that originally triggered the event (different from :cpp:func:`lv_event_get_current_target` if :ref:`event bubbling <event_bubbling>` is enabled).
- :cpp:expr:`lv_event_get_target_obj(e)`: get the Widget that originally triggered the event.
- :cpp:expr:`lv_event_get_user_data(e)`: get the pointer passed as the last parameter of :cpp:func:`lv_obj_add_event_cb`.
- :cpp:expr:`lv_event_get_param(e)`: get the parameter passed as the last parameter of :cpp:func:`lv_obj_send_event_cb`
.. tip::
When using C++, prefer :cpp:expr:`lv_event_get_target_obj(e)` over :cpp:expr:`lv_event_get_target(e)`
when you know the target is a Widget, as it returns the correct type without requiring a cast.
.. warning::
Only call :cpp:expr:`lv_event_get_target_obj(e)` when the event target is known to be a Widget.
Calling it for Display or Indev targets is considered Undefined Behavior.
.. _event_bubbling: