lv_list_add_btn has icon and symbol support. It’s great. However, I want to change the icon or the text on the fly. On a already created item. It’s a bit to complicated for me to modify. It’s a class obj so it creates some random object which I don’t know the name of.
There was support for a load of stuff with regards to list_btn in 7.11, but V8 seems to have been nerfed allot.
Is there a way to do this? I’ve tried to remove the whole button and create it again, but that only adds it to the bottom. Very messy.
Ideas, code and pointers are greatly appreciated!
EDIT: I managed to solve this issue myself, I think these functions I made should be added to the LVGL repo. First function adds a symbol to existing list button (if no img already exists). Second function can remove an image if it exists on a list button.
// ADD SYMBOL TO ALREADY EXISTING LIST BUTTON, IF NO IMG ALREADY EXISTS.
lv_obj_t * lv_list_set_btn_symbol(lv_obj_t * list, lv_obj_t * btn, const char * icon)
{
LV_UNUSED(list);
uint32_t i;
int flag=0;
Serial.println(lv_obj_get_child_cnt(btn));
for(i = 0; i < lv_obj_get_child_cnt(btn); i++) {
lv_obj_t * child = lv_obj_get_child(btn, i);
if (lv_obj_check_type(child, &lv_img_class)) {
flag++;
}
}
if (flag == 0) {
lv_obj_t * img = lv_img_create(btn);
lv_obj_align(img, LV_ALIGN_RIGHT_MID, 0, 0);
lv_img_set_src(img, icon);
}
}
// DELETE A SYMBOL FROM EXISTING LIST BUTTON
lv_obj_t * lv_list_del_btn_symbol(lv_obj_t * list, lv_obj_t * btn)
{
LV_UNUSED(list);
uint32_t i;
for(i = 0; i < lv_obj_get_child_cnt(btn); i++) {
lv_obj_t * child = lv_obj_get_child(btn, i);
if(lv_obj_check_type(child, &lv_img_class)) {
lv_obj_del(child);
}
}
}