Description
the image recolor dos not work when i add a lv_image to the lv_tabview button.what is the correct approach?
the image color is white,recolor to rgb(255,0,128) dos not work…
What MCU/Processor/Board and compiler are you using?
PC Simulator
What LVGL version are you using?
V9.0.0
What do you want to achieve?
add a lv_image to the lv_tabview button.
What have you tried so far?
lv_obj_set_style_image_recolor_opa(img, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_image_recolor(img, lv_color_make(255, 0, 128), LV_PART_MAIN);
Code to reproduce
lv_obj_t * lv_tabview_add_tab_plus(lv_obj_t * obj, char *name, const lv_image_dsc_t *imgDsc )
{
LV_ASSERT_OBJ(obj, MY_CLASS);
lv_obj_t * cont = lv_tabview_get_content(obj);
lv_obj_t * page = lv_obj_create(cont);
lv_obj_set_size(page, lv_pct(100), lv_pct(100));
uint32_t tab_idx = lv_obj_get_child_count(cont);
lv_obj_t * tab_bar = lv_tabview_get_tab_bar(obj);
lv_obj_t * button = lv_button_create(tab_bar);
lv_obj_set_flex_grow(button, 1);
lv_obj_set_size(button, lv_pct(100), lv_pct(100));
lv_obj_add_event_cb(button, button_clicked_event_cb, LV_EVENT_CLICKED, NULL);
lv_group_t * g = lv_group_get_default();
if(g) lv_group_add_obj(g, button);
lv_obj_t* img = NULL;
int32_t fontHalf = 0;
if (imgDsc)
{
img = lv_image_create(button);
lv_image_set_src(img, imgDsc);
lv_obj_set_size(img, imgDsc->header.w, imgDsc->header.h);
lv_obj_set_style_image_recolor_opa(img, LV_OPA_COVER, LV_PART_MAIN);
//lv_obj_set_style_image_recolor(img, lv_obj_get_style_text_color(button, LV_STATE_DEFAULT), LV_PART_MAIN);
lv_obj_set_style_image_recolor(img, lv_color_make(255, 0, 128), LV_PART_MAIN);
if (name)
{
fontHalf = lv_font_get_line_height(lv_obj_get_style_text_font(button, LV_PART_MAIN)) / 2;
lv_obj_align(img, LV_ALIGN_CENTER, 0, -fontHalf);
}
else
lv_obj_center(img);
}
if(name)
{
lv_obj_t * label = lv_label_create(button);
lv_label_set_text(label, name);
if (imgDsc)
{
fontHalf = imgDsc->header.h / 2;
lv_obj_align(label, LV_ALIGN_CENTER, 0, fontHalf);
//lv_obj_align_to(label, img, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
}
else
lv_obj_center(label);
}
if(tab_idx == 1) {
lv_tabview_set_active(obj, 0, LV_ANIM_OFF);
}
return page;
}