feat(obj): add API to set/get object ID. (#6278)
Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
This commit is contained in:
@@ -14,19 +14,20 @@ Usage
|
||||
-----
|
||||
|
||||
Enable this feature by setting :c:macro:`LV_USE_OBJ_ID` to `1` in ``lv_conf.h``.
|
||||
Use the builtin obj ID generator by setting :c:macro:`LV_USE_OBJ_ID_BUILTIN` to `1`.
|
||||
Otherwise provide your own custom implementation.
|
||||
|
||||
The ID is automatically generated and assigned to :cpp:expr:`obj->id` during obj's
|
||||
construction by calling API :cpp:expr:`lv_obj_assign_id(obj)` from :cpp:func:`lv_obj_constructor`.
|
||||
Enable :c:macro:`LV_OBJ_ID_AUTO_ASSIGN` to automatically assign an ID to object when it's created.
|
||||
It's done by calling function :cpp:func:`lv_obj_assign_id` from :cpp:func:`lv_obj_constructor`.
|
||||
|
||||
You can directly access the ID by :cpp:expr:`obj->id` or use API :cpp:expr:`lv_obj_stringify_id(obj, buf, len)`
|
||||
You can either use your own ID generator by defining the function :cpp:func:`lv_obj_assign_id` or you can utilize the built-in one.
|
||||
To use the builtin ID generator, set :c:macro:`LV_USE_OBJ_ID_BUILTIN` to `1`.
|
||||
|
||||
You can directly access the ID by :cpp:expr:`lv_obj_get_id(obj)` or use API :cpp:expr:`lv_obj_stringify_id(obj, buf, len)`
|
||||
to get a string representation of the ID.
|
||||
|
||||
Use custom ID generator
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Set :c:macro:`LV_USE_OBJ_ID_BUILTIN` to `0` in ``lv_conf.h``.
|
||||
Set :c:macro:`LV_USE_OBJ_ID_BUILTIN` to `0` in ``lv_conf.h``.
|
||||
|
||||
Below APIs needed to be implemented and linked to lvgl.
|
||||
|
||||
@@ -35,6 +36,7 @@ Below APIs needed to be implemented and linked to lvgl.
|
||||
void lv_obj_assign_id(const lv_obj_class_t * class_p, lv_obj_t * obj);
|
||||
void lv_obj_free_id(lv_obj_t * obj);
|
||||
const char * lv_obj_stringify_id(lv_obj_t * obj, char * buf, uint32_t len);
|
||||
int lv_obj_id_compare(void * id1, void * id2);
|
||||
|
||||
|
||||
:cpp:func:`lv_obj_assign_id` is called when an object is created. The object final class is passed from
|
||||
@@ -55,3 +57,9 @@ This is useful to debug UI crash. From log we can rebuilt UI the moment before c
|
||||
For example, if the obj is stored to a :cpp:expr:`timer->user_data`, but obj is deleted when timer expired.
|
||||
Timer callback will crash because of accessing wild pointer.
|
||||
From the dump log we can clearly see that the obj does not exist.
|
||||
|
||||
Find child by ID
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Use API :cpp:expr:`lv_obj_t * lv_obj_get_child_by_id(const lv_obj_t * obj, void * id);` to find a child by ID.
|
||||
It will walk through all children and return the first child with the given ID.
|
||||
|
||||
Reference in New Issue
Block a user