LVGL V8之 multiple styles

133 篇文章 112 订阅

创建style

  • 初时化base style
    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_PALETTE_LIGHT_BLUE
lv_style_set_border_color(&style_base, lv_palette_darken(LV_PALETTE_LIGHT_BLUE,3));
  • 设置边框线宽为2
lv_style_set_border_width(&style_base, 2);
  • 设置倒角为10
  lv_style_set_radius(&style_base, 10);
  • 设置阴影宽度为10
  lv_style_set_shadow_width(&style_base, 10);
  • 设置阴影在bottom下方出现
 lv_style_set_shadow_ofs_y(&style_base, 5);
  • 设置阴影透明度为50%
  lv_style_set_shadow_opa(&style_base, LV_OPA_50);
  • 设置文本颜色为白色
 lv_style_set_text_color(&style_base, lv_color_white());
  • 设置style宽度为100
  lv_style_set_width(&style_base, 100);
  • 设置style高度为LV_SIZE_CONTENT
lv_style_set_height(&style_base, LV_SIZE_CONTENT);
  • 初时化另一个warning style
    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));
  • 创建obj对象,添加style,居中显示
    lv_obj_t* obj_base = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj_base, &style_base, 0);
    lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 20, 0);
    lv_obj_t* label = lv_label_create(obj_base);
    lv_label_set_text(label, "Base");
    lv_obj_center(label);
    
    lv_obj_t* obj_warning = lv_obj_create(lv_scr_act());
    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, -20, 0);
    label = lv_label_create(obj_warning);
    lv_label_set_text(label, "Warning");
    lv_obj_center(label);

完整代码,仅供参考

static void lv_example_style_11(void)
{
    /*A base style*/
    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);
    /*Set only the properties that should be different*/
    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));
    /*Create an object with the base style only*/
    lv_obj_t* obj_base = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj_base, &style_base, 0);
    lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 20, 0);
    lv_obj_t* label = lv_label_create(obj_base);
    lv_label_set_text(label, "Base");
    lv_obj_center(label);
    /*Create an other object with the base style and earnings style too*/
    lv_obj_t* obj_warning = lv_obj_create(lv_scr_act());
    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, -20, 0);
    label = lv_label_create(obj_warning);
    lv_label_set_text(label, "Warning");
    lv_obj_center(label);
}

调用lv_example_style_11运行效果

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风雨依依

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值