1 #include "../../lv_examples.h"
2 #if LV_USE_CANVAS && LV_BUILD_EXAMPLES
3
4 #define CANVAS_WIDTH 50
5 #define CANVAS_HEIGHT 50
6
7 /**
8 * Draw a rectangle to the canvas
9 */
lv_example_canvas_3(void)10 void lv_example_canvas_3(void)
11 {
12 /*Create a buffer for the canvas*/
13 LV_DRAW_BUF_DEFINE_STATIC(draw_buf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_COLOR_FORMAT_ARGB8888);
14 LV_DRAW_BUF_INIT_STATIC(draw_buf);
15
16 /*Create a canvas and initialize its palette*/
17 lv_obj_t * canvas = lv_canvas_create(lv_screen_active());
18 lv_canvas_set_draw_buf(canvas, &draw_buf);
19
20 lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
21 lv_obj_center(canvas);
22
23 lv_layer_t layer;
24 lv_canvas_init_layer(canvas, &layer);
25
26 lv_draw_rect_dsc_t dsc;
27 lv_draw_rect_dsc_init(&dsc);
28 dsc.bg_color = lv_palette_main(LV_PALETTE_RED);
29 dsc.border_color = lv_palette_main(LV_PALETTE_BLUE);
30 dsc.border_width = 3;
31 dsc.outline_color = lv_palette_main(LV_PALETTE_GREEN);
32 dsc.outline_width = 2;
33 dsc.outline_pad = 2;
34 dsc.outline_opa = LV_OPA_50;
35 dsc.radius = 5;
36 dsc.border_width = 3;
37
38 lv_area_t coords = {10, 10, 40, 30};
39
40 lv_draw_rect(&layer, &dsc, &coords);
41
42 lv_canvas_finish_layer(canvas, &layer);
43 }
44 #endif
45