LVGL V8之 multiple styles
multiple V8 LVGL styles
2023-09-14 09:06:41 时间
创建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运行效果
相关文章
- input file多选 multiple[通俗易懂]
- CSS波形生成器-CSS Waves-Gradient Multiple Waves-Multiple Animated Waves
- ORA-19269: XQST0049 – variable string defined multiple times ORACLE 报错 故障修复 远程处理
- ORA-26896: Attempted to connect multiple Oracle GoldenGate Capture processes, including “string”, with XStream outbound server “string” through queue “string”.”string” ORACLE 报错 故障修复 远程处理
- ORA-27018: BLKSIZE is not a multiple of the minimum physical block size ORACLE 报错 故障修复 远程处理
- ORA-32303: mviews with user-defined types cannot reference multiple master sites ORACLE 报错 故障修复 远程处理
- ORA-44745: Cannot add or drop columns to or from multiple tables. ORACLE 报错 故障修复 远程处理
- MySQL Error number: 3953; Symbol: ER_MULTIPLE_INTO_CLAUSES; SQLSTATE: HY000 报错 故障修复 远程处理
- MySQL Error number: 3967; Symbol: ER_MULTIPLE_JSON_VALUES; SQLSTATE: 22034 报错 故障修复 远程处理
- ORA-02146: SHARED specified multiple times ORACLE 报错 故障修复 远程处理
- ORA-13339: LRS polygon clipping across multiple rings ORACLE 报错 故障修复 远程处理
- ORA-15092: I/O request size string is not a multiple of logical block size string ORACLE 报错 故障修复 远程处理
- ORA-16809: multiple warnings detected for the database ORACLE 报错 故障修复 远程处理
- MySQL Error number: MY-014009; Symbol: ER_WARN_COMPONENTS_INFRASTRUCTURE_MANIFEST_MULTIPLE_KEYRING; SQLSTATE: HY000 报错 故障修复 远程处理
- Efficient Sorting with Multiple Conditions in MySQL(mysql多条件排序)
- Efficient Sorting Techniques for Multiple Fields in Oracle Databases(oracle多字段排序)
- Exploring the Benefits and Challenges of Implementing a MySQL Multidatabase Architecture with Multiple Data Centers.(mysql多数据中心)
- Efficient Redis Queries with Multiple Conditions: A Guide(redis多条件查询)