What i am currently missing is a function to assign an id/name to an object and search for objects. The current object id (LV_USE_OBJ_ID) can not be set directly. Something like document.getElementById(…).
I can implement this feature if desired and if we can agree on an API.
I think that would work like most people would expect that feature to work.
The other question is how to set the id, i think there are multiple possible ways:
Combine it with the existing OBJ_ID feature and create a new method: lv_obj_set_id(obj, "id")
This call would replace the id from lv_obj_assign_id with the new id. This might be the easiest way to implement the feature but feels hacky to me, because obj->id is of type void*.
Create new fields next to obj->id and global->objid_array/objid_count and add a method to set the name (id is used by OBJ_ID): lv_obj_set_name(obj, "name")
The method should verify that names are unique.
It is possible to handle the names without adding a field to the object and store all required informations in global (name and pointer to object pairs).
Ok, to sum things up. There are 3 methods required to implement this:
lv_obj_get_child_by_id/ lv_obj_get_child_by_name
lv_display_get_obj_by_id / lv_display_get_obj_by_name
lv_obj_set_id / lv_obj_set_name // calling with NULL as id would delete the id
I’m not sure if the term id should be used here, because there is already another feature called obj_id.
I would suggest to create an array or list of lv_obj_t*/char* pairs in lv_global_t and add an entry for each object that the user defined an id for. This implemantation would store anything in the global struct.
Pro:
no need the change lv_obj_t struct
Con:
on every obj delete the entire list of pairs must be searched if there is an entry for the object
To avoid the search on every delete, a bool has_id could be added to lv_obj_t.
This is what I used to use in my ui applications:
The idea is that there should exist a function called lv_obj_get_name() that returns the name of the object passed as param, this way we can define the function find_child that search for a child of the obj passed as first arg having the name passa as second arg.
Hi Gabor, this is just a pseudo code derived from my previous work, a bin is a widget containing one child, a container is a widget containing more children.