Hello. I add elements like this:
#include "../../lv_examples.h"
lv_obj_t * list1 = lv_list_create(lv_scr_act());
lv_obj_t * btn;
lv_obj_set_size(list1, 200, 220);
lv_obj_center(list1);
while (...){
btn = lv_list_add_btn(list1, "some text");
}
So I have few elements on the list. And now the main question: how can i get access to the 1-st, 2-nd etc… element? I need to modify them (change the text, remove etc…)
What MCU/Processor/Board and compiler are you using?
Arduino 1.8 / ESP32
What LVGL version are you using?
8.3
What have you tried so far?
Nothing
elgerg
December 1, 2022, 5:28pm
2
I’m not sure if this is the best approach but it has worked for me without any problems so far.
Outside of the init/loop I created a struct with the maximum number of items I expect:
struct roomItem
{
char TileName[20];
char ObjectName[20];
char ObjectType[10];
char ObjectTopic[30];
lv_obj_t * LVObject;
lv_obj_t * LVLabelObject;
lv_obj_t * PopupLVObject;
lv_obj_t * PopupLVLabelObject;
} roomItems[50];
Then in the creation loop I set the values as required:
value = json_object_get_string(tile_holder);
strcpy(roomItems[objectID].ObjectType, value);
roomItems[objectID].LVObject = retVal.obj;
roomItems[objectID].LVLabelObject = retVal.label;
You can then lookup the specific struct (and therefore button) by name etc using something like:
for (int i = 0; i < 50; i++)
{
if(strcmp(roomItems[i].ObjectTopic, json_object_get_string(topic_struct)) == 0)
{
if(strcmp(roomItems[i].ObjectType, "Dimmer") == 0)
{
struct json_object *percentage_struct;
json_object_object_get_ex(parsed_json, "percentage", &percentage_struct);
int level = json_object_get_int(percentage_struct);
json_object_put(percentage_struct);
setSlider(roomItems[i].LVObject, roomItems[i].LVLabelObject, level);
if(roomItems[i].PopupLVObject != NULL)
{
setSlider(roomItems[i].PopupLVObject, roomItems[i].PopupLVLabelObject, level);
}
}
Hope that helps
Thanks for yout answer, but it is not my case.
I hope there in LVGL is something like LVobj_get_child[x] but can not find in manuals
I found out this:
lv_obj_t * child = lv_obj_get_child(parent, NULL);
while(child) {
/*Do something with "child" */
child = lv_obj_get_child(parent, child);
}
and this
lv_obj_count_children(obj)