这一篇来学一下multiple styles,多种样式的组合使用,还是通过codeblock来模拟代码的运行,代码如下:
void lv_multiple_style_test()
{
static lv_style_t style_base;
lv_style_init(&style_base);
lv_style_set_bg_color(&style_base, lv_palette_main(LV_PALETTE_LIGHT_BLUE));
lv_style_set_border_color(&style_base, lv_palette_darken(LV_PALETTE_LIGHT_BLUE, 3));
lv_style_set_border_width(&style_base, 2);
lv_style_set_radius(&style_base, 10);
lv_style_set_shadow_width(&style_base, 10);
lv_style_set_shadow_ofs_y(&style_base, 5);
lv_style_set_shadow_opa(&style_base, LV_OPA_50);
lv_style_set_text_color(&style_base, lv_color_white());
lv_style_set_width(&style_base, 100);
lv_style_set_height(&style_base, LV_SIZE_CONTENT);
static lv_style_t style_warning;
lv_style_init(&style_warning);
lv_style_set_bg_color(&style_warning, lv_palette_main(LV_PALETTE_YELLOW));
lv_style_set_border_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 3));
lv_style_set_text_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 4));
lv_obj_t * label = NULL;
lv_obj_t * obj_base = lv_obj_create(lv_scr_act());
if (obj_base != NULL)
{
lv_obj_add_style(obj_base, &style_base, 0);
lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 200, 0);
label = lv_label_create(obj_base);
if (label != NULL)
{
lv_label_set_text(label, "Base");
lv_obj_center(label);
}
}
lv_obj_t * obj_warning = lv_obj_create(lv_scr_act());
if (obj_warning != NULL)
{
lv_obj_add_style(obj_warning, &style_base, 0);
lv_obj_add_style(obj_warning, &style_warning, 0);
lv_obj_align(obj_warning, LV_ALIGN_RIGHT_MID, -200, 0);
label = lv_label_create(obj_warning);
if (label != NULL)
{
lv_label_set_text(label, "Warning");
lv_obj_center(label);
}
}
}
运行效果: