当前位置:网站首页>[lvgl (5)] label usage
[lvgl (5)] label usage
2022-07-24 06:46:00 【Like warm know cold】
The official manual :Label (lv_label) — LVGL documentation
https://docs.lvgl.io/master/widgets/core/label.html
label (lv_label)
Labels are the basic object types used to display text .
In the box model , Composition of labels :
- LV_PART_MAIN Rectangular part ( Box area ). Fill values can be used to add space between text and background .
- LV_PART_SCROLLBAR When the text to be displayed is larger than the size of the part , Scroll bar part of the display .
- LV_PART_SELECTED When text is selected , Highlighted part .label Only use text_color and bg_color Style attribute
Create a label
lv_obj_t * label = lv_label_create(parent);Set text
Set the text to display
Dynamically allocate buffers , Do not keep the passed text .
lv_label_set_text(label, "HELLOW LVGL");It can also display text from the static character buffer . Text is not stored in dynamic memory , Instead, use the given buffer directly .
lv_label_set_text_static(label, "Text")Format the display text
lv_label_set_text_fmt(label, "Value: %d", 15)Line break
Use \n Line break , for example :
lv_label_set_text(label, "line1\nline2\n\nline4");Set text size
By default, the size of the label is set to LV_SIZE_CONTENT It will automatically expand to the same size as the text .
If width or height is set , Text wider than the label width can be manipulated according to several long mode strategies .
lv_obj_set_width(label,50); // Set width
lv_obj_set_height(label,20); // Set height
lv_obj_set_size(label,20,50);
In this way, the width or height of the text may appear label The situation of , You need to make some adjustments .
- LV_LABEL_LONG_WRAP: Wrap too long . If the height is LV_SIZE_CONTENT The height of the label will be expanded , Otherwise the text will be clipped . ( Default )
- LV_LABEL_LONG_DOT: Place the bottom right corner of the label at the end 3 Characters replaced with dots ( ...)
- LV_LABEL_LONG_SCROLL: If the text is wider than the label , Then scroll back and forth horizontally . If it is higher , Please scroll vertically . Scroll in only one direction , Horizontal scrolling has a higher priority .
- LV_LABEL_LONG_SCROLL_CIRCULAR: If the text is wider than the label , Then continuous horizontal scrolling . If it is higher , Please scroll vertically . Scroll in only one direction , Horizontal scrolling has a higher priority .
- LV_LABEL_LONG_CLIP: Just cut the text outside the label
Be careful :LV_LABEL_LONG_DOT yes Directly manipulate the text buffer to add / Delete point . If you use lv_label_set_text and lv_label_set_text_fmt They allocate a separate buffer , No problem . But if you use lv_label_set_text_static The buffer we pass to it must be writable .
Set interface
lv_label_set_long_mode(label, LV_LABEL_LONG_...)Set the font style
Setting a custom font is the same
lv_obj_t * label = lv_label_create(lv_scr_act()); // Create a label parts ( object ), Its parent object is the active screen object
lv_obj_set_style_text_font(label, &lv_font_simsun_16_cjk, 0); // Use the built-in cjk Word stock
lv_label_set_text(label, "text");Recolor text
Change the label color
lv_obj_set_style_bg_color(label, lv_color_hex(0xf7b37b), 0);
lv_obj_set_style_bg_opa(label, 100, 0); // The opacity You can change the color by style
lv_style_set_text_color(&style_obj, lv_color_hex(0xf7b37b)); // Shared styles
lv_obj_set_style_text_color(label, lv_color_hex(0xf7b37b), 0); // Local style
You can recolor some parts of the text
explain :#0000ff Re-color#: Color value :0x0000ff, Change the text :Re-color
lv_label_set_recolor(label, true);
lv_label_set_text(label, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label");Text selection
If in lv_conf.h Open in LV_LABEL_TEXT_SELECTION ( Default on ), You can select part of the text . This is with us PC Selecting text with the mouse is similar , But this effect can only be in the text box (lv_textarea) To realize .Label You can only manually select the text of the specified range in advance
lv_label_get_text_selection_start(label, start_char_index);
lv_label_get_text_selection_start(label, end_char_index);lv_label_set_text_sel_start(label, 1);
lv_label_set_text_sel_end(label, 6);
Built in icon

Show icons directly
lv_label_set_text(my_label, LV_SYMBOL_OK);Use with strings
lv_label_set_text(my_label, LV_SYMBOL_OK "Apply");Many icons together
lv_label_set_text(my_label, LV_SYMBOL_OK LV_SYMBOL_WIFI LV_SYMBOL_PLAY);event
Label Input events are not received by default , If we want to set the style or event of input type, it will not take effect , It needs to be opened LV_OBJ_FLAG_CLICKABLE
lv_obj_add_flag(label, LV_OBJ_FLAG_CLICKABLE);
lv_obj_add_event_cb(label, function, LV_EVENT_ALL, 0);边栏推荐
- 【LVGL(重要)】样式属性API函数及其参数
- Quick start of go language
- These 10 kinds of timed tasks have been learned, and you can float directly
- Why can't index be the key of V-for?
- 今天聊赖数据库MySQL底层架构设计,你了解多少?
- LM393 电压比较器及其典型电路介绍
- Introduction to kubernetes (kubernetes benefits)
- kubernetes简介(kubernetes优点)
- Kubernetes rapid installation
- Animation effect
猜你喜欢

Several common problems of SQL server synchronization database without public IP across network segments

磁盘管理和文件系统

Restful API introduction

Redis.conf详解

Solution: exit status 1 and exit status 145 appear when the console uses NVM to control the node version

sojson jsjiami.com.v6 爬虫js逆向

目录和文件管理

JMeter distributed pressure measurement

Explain the event cycle mechanism and differences between browser and node in detail

【LVGL】组件的样式的设置、更改、删除API函数
随机推荐
Redis基本类型-有序集合Zset
Go environment construction and start
MGR_mysqlsh_keepalive高可用架构部署文档
Jenkins CI CD
United Nations agricultural products data analysis
Jenkins CI CD
Sed command
【小型物体测速仪】只有原理,无代码
带你深入了解MySQL数据库扣减库存原理
Rsync (I): basic commands and usage
这些坑你不掌握,你还真不敢用BigDecimal
基于回归分析的广告投入销售额预测——K邻近,决策树,随机森林,线性回归,岭回归
Secondary processing of template data
Backup MySQL database with bat script under Windows
Yiwen node installation, download and configuration
Multiple types of functions
NFS共享服务及实验
[lvgl (2)]
系统安全及应用
【LVGL(3)】设置对象大小、位置、盒子模型、状态