当前位置:网站首页>Lvgl widget styles
Lvgl widget styles
2022-06-30 12:13:00 【Passing bear~】
brief introduction
The style setting is LVGL in , To make a beautiful UI Interface is an indispensable and necessary element .
lvgl Style description
lvgl Style of size 、 Location and fill style attribute settings
Use code examples :
static lv_style_t style;
lv_style_init(&style);
// Set the style fillet radius
lv_style_set_radius(&style, 5);
// Set size style
lv_style_set_width(&style, 150);
lv_style_set_height(&style, LV_SIZE_CONTENT);
// Set the fill pattern
lv_style_set_pad_ver(&style, 20);
lv_style_set_pad_left(&style, 5);
// Set position style
lv_style_set_x(&style, lv_pct(50));
lv_style_set_y(&style, 80);
/* Create an object using the new style */
lv_obj_t * obj = lv_obj_create(lv_scr_act());
lv_obj_add_style(obj, &style, 0);
lv_obj_t * label = lv_label_create(obj);
lv_label_set_text(label, "Hello");
The effect is as follows :
lvgl Style of Background color 、 Border color 、 The outer margin property is set
Example code :
// Create a container
static const lv_style_prop_t props[] = {
LV_STYLE_BG_COLOR, LV_STYLE_BORDER_COLOR, LV_STYLE_BORDER_WIDTH, 0};
/* A default style * Time delay 100ms start-up , Delay 200ms After that */
static lv_style_transition_dsc_t trans_def;
lv_style_transition_dsc_init(&trans_def, props, lv_anim_path_linear, 100, 200, NULL);
/* A special style in the pressed state * Delay 500ms start-up , But do not delay the end */
static lv_style_transition_dsc_t trans_pr;
lv_style_transition_dsc_init(&trans_pr, props, lv_anim_path_linear, 500, 0, NULL);
static lv_style_t style_def;
// Create styles
lv_style_init(&style_def);
// Add a predetermined default state to the style style_def in
lv_style_set_transition(&style_def, &trans_def);
static lv_style_t style_pr;
// Create styles
lv_style_init(&style_pr);
// Style background color : Red
lv_style_set_bg_color(&style_pr, lv_palette_main(LV_PALETTE_RED));
// Style outer margin :6pix
lv_style_set_border_width(&style_pr, 6);
// Style border color : Blue
lv_style_set_border_color(&style_pr, lv_palette_darken(LV_PALETTE_BLUE, 3));
// Add the scheduled press style to style_pr in
lv_style_set_transition(&style_pr, &trans_pr);
/* Create an object , Used to make the style effective */
#if 0
// Common styles
LV_STATE_DEFAULT = 0x0000,
LV_STATE_CHECKED = 0x0001,
LV_STATE_FOCUSED = 0x0002,
LV_STATE_FOCUS_KEY = 0x0004,
LV_STATE_EDITED = 0x0008,
LV_STATE_HOVERED = 0x0010,
LV_STATE_PRESSED = 0x0020,
LV_STATE_SCROLLED = 0x0040,
LV_STATE_DISABLED = 0x0080,
LV_STATE_USER_1 = 0x1000,
LV_STATE_USER_2 = 0x2000,
LV_STATE_USER_3 = 0x4000,
LV_STATE_USER_4 = 0x8000,
#endif
// Create objects
lv_obj_t * obj = lv_obj_create(lv_scr_act());
// take style_def Set as default style
lv_obj_add_style(obj, &style_def, 0);
// take style_pr Set to press style
lv_obj_add_style(obj, &style_pr, LV_STATE_PRESSED);
lv_obj_center(obj);
The effect is as follows :
After clicking , The effect is as follows :
lvgl Style of Text style attribute settings
Use code examples :
// Create styles
static lv_style_t style;
// Initialize style
lv_style_init(&style);
// Set the background fillet radius to : 5
lv_style_set_radius(&style, 5);
// Set background transparency
lv_style_set_bg_opa(&style, LV_OPA_COVER);
// Set the background color
lv_style_set_bg_color(&style, lv_palette_lighten(LV_PALETTE_GREY, 2));
// Set the outer margin to : 2
lv_style_set_b:order_width(&style, 2);
// Set the outer border color to blue
lv_style_set_border_color(&style, lv_palette_main(LV_PALETTE_BLUE));
// Set the fill
lv_style_set_pad_all(&style, 10);
// Set the color of the text style : Blue
lv_style_set_text_color(&style, lv_palette_main(LV_PALETTE_BLUE));
// Set the spacing between text styles : 5
lv_style_set_text_letter_space(&style, 5);
// Set the line spacing of the text style : 20
lv_style_set_text_line_space(&style, 20);
// Set text style underline
lv_style_set_text_decor(&style, LV_TEXT_DECOR_UNDERLINE);
/*Create an object with the new style*/
lv_obj_t * obj = lv_label_create(lv_scr_act());
lv_obj_add_style(obj, &style, 0);
lv_label_set_text(obj, "Text of\n"
"a label");
lv_obj_center(obj);
The effect is as follows :
In addition
...
边栏推荐
- Conference Preview - Huawei 2012 lab global software technology summit - European session
- 并行接口8255A
- R language ggplot2 visualization: use ggplot2 to visualize the scatter diagram and use scale_ color_ viridis_ D function specifies the color scheme of data points
- 用宝塔建第2个网站时网站总是报错:No input file specified.
- Time function and clock_ Differences between gettime() functions
- MySQL索引和优化的理解学习
- 来聊聊怎么做硬件兼容性检测,快速迁移到openEuler?
- 实现多方数据安全共享,解决普惠金融信息不对称难题
- 3D线光谱共焦传感器在半导体如何检测
- Statistics on the number of closed Islands
猜你喜欢

Biological network analysis using deep learning

【云原生 | Kubernetes篇】深入了解Deployment(八)

How can c write an SQL parser

ZABBIX monitors the number of TCP connections

Let's talk about how to do hardware compatibility testing and quickly migrate to openeuler?

Joplin实现样式更改

光谱共焦位移传感器的原理是什么?能应用那些领域?

聊聊怎么做硬件兼容性检测,快速迁移到openEuler?

Another miserable day by kotlin grammar

Set集合
随机推荐
论文解读(AGC)《Attributed Graph Clustering via Adaptive Graph Convolution》
List集合
DMA控制器8237A
R language ggplot2 visual Facet: gganimate package is based on Transition_ The time function creates a dynamic scatter graph animation (GIF) and uses the labs function to add a dynamic time title to t
A High-Precision Positioning Approach for Catenary Support Components With Multiscale Difference阅读笔记
Redis6学习笔记-第二章-Redis6的基本操作
How can c write an SQL parser
服务器常用的一些硬件信息(不断更新)
解决服务器重装无法通过ssh连接的问题
Set集合
21、wpf之绑定使用小记
8253计数器介绍
wallys/IPQ8074a/2x(4 × 4 or 8 × 8) 11AX MU-MIMO DUAL CONCURRENT EMBEDDEDBOARD
Let's talk about how to do hardware compatibility testing and quickly migrate to openeuler?
Cache avalanche and cache penetration solutions
OpenMLDB Meetup No.4 会议纪要
1175. 质数排列 : 乘法原理运用题
Paper interpretation (AGC) attributed graph clustering via adaptive graph revolution
爱可可AI前沿推介(6.30)
Go 语言入门很简单:Go 处理 XML 文件