Description
Creating multiple label widget on single screen with different size, style and color
What MCU/Processor/Board and compiler are you using?
STM32 MCU
What LVGL version are you using?
8.3
What do you want to achieve?
I am trying to add multiple labels (lv_label_create) on single screen with different style. I am using lv_style_t object for style. Not sure if this is proper way to do.
What have you tried so far?
Tried to use single object of lv_obj_t and lv_style_t but last style gets applied to all label on screen.
Tried to use array of lv_obj_t object and single lv_style_t object and same observation as above.
Code to reproduce
lv_style_t obj_style;
for( k =0 ; k <5 ; k++ )
{
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_style_init(&obj_style);
lv_obj_add_style(label, &obj_style, LV_PART_MAIN);
lv_color_t clr = lv_color_hex(color[k]);
lv_style_set_text_color(&obj_style, clr);
lv_style_set_text_font(&text_style, &font[k]);
lv_label_set_text(label,labeltext[k]);
lv_obj_align(label, LV_ALIGN_TOP_LEFT, x[k], y[k]);
}
/*Another approach */
lv_style_t obj_style;
lv_obj_t * label[5];
for( k =0 ; k <5 ; k++ )
{
label[k] = lv_label_create(lv_scr_act());
lv_style_init(&obj_style);
lv_obj_add_style(label[k], &obj_style, LV_PART_MAIN);
lv_color_t clr = lv_color_hex(color[k]);
lv_style_set_text_color(&obj_style, clr);
lv_style_set_text_font(&text_style, &font[k]);
lv_label_set_text(label[k],labeltext[k]);
lv_obj_align(label[k], LV_ALIGN_TOP_LEFT, x[k], y[k]);
}
Screenshot and/or video
Last style of label gets applied to all labels on screen and different styles are not seen. Not sure what is proper way to handle this like array of lv_obj_t and lv_style_t.