Does anyone know how to create objects dynamically, is that possible? For example, a controller scanned some radio network and found number of sensors, how to create labels on a screen according to the number of sensors found?
I am using version 7.11 in simulator. Code example:
// Dynamic allocation of objects
lv_coord_t Y_POS = 40;
for (int i = 0; i < sen_num; i++) { #if EVENTS_DEBUG
printf("%s\n", sensors[i].name); #endif
lv_obj_t * lbl_sen[i] = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(lbl_sen[i], sensors[i].name);
lv_obj_add_style(lbl_sen[i], LV_BTN_PART_MAIN, &style_lbl_dt);
lv_obj_align(lbl_sen[i], NULL, LV_ALIGN_IN_TOP_LEFT, 20, Y_POS + 20);
}
It reports an error: “Expression must have a constant value” so it does not allow sen[i], any other way?
Thanks.
I have changed declaration to:
lv_obj_t * lbl_sen[sen_num];
but still requires sen_num to have constant value in that expression.
It works when I put a number.