当前位置:网站首页>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

边栏推荐
- C language programming
- [MySQL from introduction to proficiency] [advanced chapter] (V) SQL statement execution process of MySQL
- Programmer turns direction
- 使用CLion编译OGLPG-9th-Edition源码
- [information retrieval] experiment of classification and clustering
- GCC [6] - 4 stages of compilation
- ML之shap:基于boston波士顿房价回归预测数据集利用Shap值对LiR线性回归模型实现可解释性案例
- R language uses follow up of epidisplay package The plot function visualizes the longitudinal follow-up map of multiple ID (case) monitoring indicators, and uses stress The col parameter specifies the
- 关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
- Leetcode T47: 全排列II
猜你喜欢

Nowcoder rearrange linked list

Leetcode 61: rotating linked list

What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?

基于51单片机的超声波测距仪

【C语言】指针笔试题

LVGL 8.2 text shadow

Docker compose public network deployment redis sentinel mode

Sqlserver functions, creation and use of stored procedures

SqlServer函数,存储过程的创建和使用
![leetcode:6109. Number of people who know the secret [definition of DP]](/img/95/03e2606b249f26db052cf5075041c1.png)
leetcode:6109. Number of people who know the secret [definition of DP]
随机推荐
LVGL 8.2 keyboard
92. (cesium chapter) cesium building layering
SqlServer函数,存储过程的创建和使用
Redis daily notes
产业互联网则具备更大的发展潜能,具备更多的行业场景
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
Digi XBee 3 rf: 4 protocols, 3 packages, 10 major functions
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
Abnormal value detection using shap value
NowCoder 反转链表
流行框架:Glide的使用
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
redis 日常笔记
MySQL stored procedure exercise
数据埋点的一些问题和想法
LVGL 8.2 Menu
深度学习7 Transformer系列实例分割Mask2Former
利用Shap值进行异常值检测
Detailed explanation of visual studio debugging methods
Codeforce:c. sum of substrings