当前位置:网站首页>LVGL 8.2 Draw label with gradient color
LVGL 8.2 Draw label with gradient color
2022-07-04 14:35:00 【Fairy sword love】
Event handling callback function
static void add_mask_event_cb(lv_event_t* e)
{
static lv_draw_mask_map_param_t m;
static int16_t mask_id;
lv_event_code_t code = lv_event_get_code(e); // Get the event code generated by the object
lv_obj_t* obj = lv_event_get_target(e); // Get the object that generated the event
lv_opa_t* mask_map = lv_event_get_user_data(e); // Get the user data associated with the event object
if (code == LV_EVENT_COVER_CHECK) {
// LV_EVENT_COVER_CHECK event
lv_event_set_cover_res(e, LV_COVER_RES_MASKED); // Set up LV_COVER_RES_MASKED
}
else if (code == LV_EVENT_DRAW_MAIN_BEGIN) {
// LV_EVENT_DRAW_MAIN_BEGIN event
lv_draw_mask_map_init(&m, &obj->coords, mask_map);
mask_id = lv_draw_mask_add(&m, NULL); // add to mask Drawing parameters
}
else if (code == LV_EVENT_DRAW_MAIN_END) {
// LV_EVENT_DRAW_MAIN_END event
lv_draw_mask_free_param(&m); // Release mask Memory occupied by drawing parameters
lv_draw_mask_remove_id(mask_id); // remove mask Drawing parameters
}
}
Draw label with gradient color
#define MASK_WIDTH 100
#define MASK_HEIGHT 45
static void lv_example_label_4(void)
{
/* Create the mask of a text by drawing it to a canvas*/
static lv_opa_t mask_map[MASK_WIDTH * MASK_HEIGHT]; // mask map Array
/*Create a "8 bit alpha" canvas and clear it*/
lv_obj_t* canvas = lv_canvas_create(lv_scr_act()); // Create a canvas
lv_canvas_set_buffer(canvas, mask_map, MASK_WIDTH, MASK_HEIGHT, LV_IMG_CF_ALPHA_8BIT); // Set canvas data buffer
lv_canvas_fill_bg(canvas, lv_color_black(), LV_OPA_TRANSP); // The canvas is filled with black , Transparency is LV_OPA_TRANSP
/*Draw a label to the canvas. The result "image" will be used as mask*/
lv_draw_label_dsc_t label_dsc; // Draw descriptor variable definitions
lv_draw_label_dsc_init(&label_dsc);
label_dsc.color = lv_color_white(); // white
label_dsc.align = LV_TEXT_ALIGN_CENTER; // LV_TEXT_ALIGN_CENTER Alignment mode
lv_canvas_draw_text(canvas, 5, 5, MASK_WIDTH, &label_dsc, "Text with gradient"); // Draw text on the canvas
/*The mask is reads the canvas is not required anymore*/
lv_obj_del(canvas); // Delete canvas
/* Create an object from where the text will be masked out. * Now it's a rectangle with a gradient but it could be an image too*/
lv_obj_t* grad = lv_obj_create(lv_scr_act()); // Create objects
lv_obj_set_size(grad, MASK_WIDTH, MASK_HEIGHT); // Set size
lv_obj_center(grad); // Align center
lv_obj_set_style_bg_color(grad, lv_color_hex(0xff0000), 0); // Set the background
lv_obj_set_style_bg_grad_color(grad, lv_color_hex(0x0000ff), 0); // Set the gradient color value
lv_obj_set_style_bg_grad_dir(grad, LV_GRAD_DIR_HOR, 0);// Set the color gradient along the horizontal direction
lv_obj_add_event_cb(grad, add_mask_event_cb, LV_EVENT_ALL, mask_map);// Add all events
}
Running effect
边栏推荐
- An overview of 2D human posture estimation
- [MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
- 【MySQL从入门到精通】【高级篇】(四)MySQL权限管理与控制
- Map of mL: Based on Boston house price regression prediction data set, an interpretable case of xgboost model using map value
- Chapter 16 string localization and message Dictionary (2)
- Data Lake (13): spark and iceberg integrate DDL operations
- 【信息检索】链接分析
- 实战解惑 | OpenCV中如何提取不规则ROI区域
- Respect others' behavior
- LVLG 8.2 circular scrolling animation of a label
猜你喜欢
Red envelope activity design in e-commerce system
flink sql-client. SH tutorial
实时数据仓库
[information retrieval] link analysis
Ultrasonic distance meter based on 51 single chip microcomputer
Visual Studio调试方式详解
电商系统中红包活动设计
【MySQL从入门到精通】【高级篇】(五)MySQL的SQL语句执行流程
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
随机推荐
(1) The standard of performance tuning and the correct posture for tuning - if you have performance problems, go to the heapdump performance community!
sql优化之explain
Count the running time of PHP program and set the maximum running time of PHP
Leetcode T48: rotating images
Leetcode 61: rotating linked list
【C语言】指针笔试题
Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
【云原生】我怎么会和这个数据库杠上了?
codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
Map of mL: Based on Boston house price regression prediction data set, an interpretable case is realized by using the map value to the LIR linear regression model
LVGL 8.2 LED
Leetcode t49: grouping of alphabetic words
Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
Ruiji takeout notes
一种架构来完成所有任务—Transformer架构正在以一己之力统一AI江湖
商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design
Detailed explanation of visual studio debugging methods
失败率高达80%,企业数字化转型路上有哪些挑战?
AI and Life Sciences