LVGL V8之 multiple styles

news/2024/7/23 9:45:43

创建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运行效果

在这里插入图片描述


http://www.niftyadmin.cn/n/1226646.html

相关文章

构建Python,Raspberry Pi和PostgreSQL数据服务器

视频教程 PostgreSQL初学者学习Raspberry PiLinux初学者指南 在Raspberry Pi安装和设置PostgreSQL 前提 下载Raspbian 格式化SD卡 使用Disk Utility在macOS中格式化SD卡 在Linux中格式化SD卡 使用gparted格式化SD卡 视频演示:如何在Raspbian安装PostgreSQL…

LVGL V8之Local styles

创建style 初时化style static lv_style_t style;lv_style_init(&style);设置背景颜色 lv_style_set_bg_color(&style, lv_palette_main(LV_PALETTE_GREEN));设置边框颜色 lv_style_set_border_color(&style, lv_palette_lighten(LV_PALETTE_GREEN, 3));设置边框宽…

使用MySQL Connector/Python访问MySQL

视频教程 从SQL入门到专家:MySQL版-使用MySQL掌握SQL完整的Python课程:通过实践学习Python将MySQL数据库与Python结合使用 本文主要关注: 如何安装MySQL Connector/Python并使用其功能访问MySQL数据库使用Python执行MySQL CRUD操作&#x…

LVGL V8之Add styles to parts and state

创建style 初时style static lv_style_t style_indic;lv_style_init(&style_indic);设置背景色为淡红色 lv_style_set_bg_color(&style_indic, lv_palette_lighten(LV_PALETTE_RED, 3));设置渐变颜色为红色 lv_style_set_bg_grad_color(&style_indic, lv_palett…

构建Python,Raspberry Pi和MySQL数据服务器

MySQL是世界上最流行的关系数据库系统之一,并且是大多数LAMP(Linux,Apache,MYSQL和PHP)栈中的常见组件。它是帮助驱动现代网络的技术之一。 诸如MYSQL之类的数据库通常是动态网站的关键组件,并且是为Web应…

LVGL V8之Extending the current theme

创建theme 定义style变量 static lv_style_t style_btn;theme回调处理 static void new_theme_apply_cb(lv_theme_t* th, lv_obj_t* obj) {LV_UNUSED(th);if (lv_obj_check_type(obj, &lv_btn_class)) //检查是否为Button class{lv_obj_add_style(obj, &style_btn, …

Python版Socket(套接字)应用-客户端和服务器

套接字可以配置为充当服务器并侦听传入的消息,或者作为客户端连接到其他应用程序。连接TCP / IP套接字的两端后,将进行双向通信。 回显服务器 回显客户端 简单客户端连接 选择侦听地址 多线程服务器 视频演示文本内容 发送和接受数据缓冲和流数据…

Python版SSH远程服务器使用Paramiko和scp库

作为开发人员,配置或调试VPS通常是无法解决的,而且并不是特别有意义。 充其量,您的应用程序可能最终将以与本地环境相同的方式运行。 我们如何才能使这一不可避免的工作变得更好? 好吧,我们可以使其自动化。 设置SSH密…