lvgl 画一个对号
lvgl 绘制一个对号,可以用canvas绘制两个三角形实现
static void func_icon_free(lv_event_t * e)
{
lv_mem_free(e->user_data);
}
static lv_obj_t *crate_icon_ok(lv_obj_t *parent, lv_coord_t width, lv_coord_t height)
{
lv_color_t *cbuf = (lv_color_t *)lv_mem_alloc(LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(width, height));
if (!cbuf) return NULL;
lv_memset_00(cbuf, LV_CANVAS_BUF_SIZE_TRUE_COLOR_ALPHA(width, height));
lv_draw_rect_dsc_t rect_dsc;
lv_draw_rect_dsc_init(&rect_dsc);
rect_dsc.radius = 0;
rect_dsc.bg_opa = LV_OPA_COVER;
rect_dsc.bg_grad.dir = LV_GRAD_DIR_VER;
rect_dsc.bg_grad.stops[0].color = lv_palette_main(LV_PALETTE_GREEN);
rect_dsc.bg_grad.stops[1].color = lv_palette_main(LV_PALETTE_LIGHT_GREEN);
rect_dsc.border_width = 0;
rect_dsc.border_opa = LV_OPA_90;
rect_dsc.border_color = lv_color_white();
rect_dsc.shadow_width = 0;
rect_dsc.shadow_ofs_x = 0;
rect_dsc.shadow_ofs_y = 0;
lv_point_t points1[3], points2[3];
points1[0].x = 0; points1[0].y = height * 2 / 4;
points1[1].x = width / 4; points1[1].y = height;
points1[2].x = width / 4; points1[2].y = height * 3 / 4;
points2[0].x = width / 4; points2[0].y = height;
points2[1].x = width; points2[1].y = 0;
points2[2].x = width / 4; points2[2].y = height * 3 / 4;
lv_obj_t * canvas = lv_canvas_create(parent);
lv_canvas_set_buffer(canvas, cbuf, width, height, LV_IMG_CF_TRUE_COLOR_ALPHA);
lv_obj_center(canvas);
lv_canvas_draw_polygon(canvas,points1,3,&rect_dsc);
lv_canvas_draw_polygon(canvas,points2,3,&rect_dsc);
lv_obj_add_event_cb(canvas, func_icon_free, LV_EVENT_DELETE,cbuf);
return canvas;
}
/*应用(在网上看到的一段代码)
if(1){
lv_obj_t *yes=crate_icon_ok(lv_scr_act(),100,100);
lv_obj_set_style_border_width(yes,2,0);
lv_obj_set_style_border_color(yes,lv_color_make(255,255,255),0);
lv_obj_align(yes, LV_ALIGN_CENTER, 0, 0);
}
*/


浙公网安备 33010602011771号