Sasa
March 20, 2024, 9:52am
1
Hi guys,
how can i access to components in a loop.?
My problem is in this case ui_Panel1, ui_Panel2 etc.
lv_label_set_text(ui_comp_get_child(ui_Panel1, UI_COMP_PANEL_LABEL), Buffer.item_name[0]);
lv_label_set_text(ui_comp_get_child(ui_Panel2, UI_COMP_PANEL_LABEL), Buffer.item_name[1]);
lv_label_set_text(ui_comp_get_child(ui_Panel2, UI_COMP_PANEL_LABEL), Buffer.item_name[2]);
lv_label_set_text(ui_comp_get_child(ui_Panel3, UI_COMP_PANEL_LABEL), Buffer.item_name[3]);
best regards
Hermit
March 20, 2024, 8:03pm
2
I guess you want to assign texts from a string array to different panels in a for loop. You need to create an array of pointers to the lv_obj_t* panel-object pointers, and assign the string array’s elements to them in the loop. Something like this:
enum { PANEL_COUNT = 3 };
static lv_obj_t* *Panels [PANEL_COUNT] = { &ui_Panel1, &ui_Panel2, &ui_Panel3 };
for (unsigned char i=0; i<PANEL_COUNT; ++i) {
lv_label_set_text( ui_comp_get_child( *Panels[i], UI_COMP_PANEL_LABEL ), Buffer.item_name[i] );
}
Sasa
March 21, 2024, 6:51am
3
Thanks for the gret Tip Hermit ! That works!
1 Like
Hermit
March 26, 2024, 8:03am
4
You’re welcome, it’s good to see that this solution is working for your project.