1_CANVAS_WIDTH = 200
2_CANVAS_HEIGHT = 150
3LV_IMG_ZOOM_NONE = 256
4
5rect_dsc = lv.draw_rect_dsc_t()
6rect_dsc.init()
7rect_dsc.radius = 10
8rect_dsc.bg_opa = lv.OPA.COVER
9rect_dsc.bg_grad.dir = lv.GRAD_DIR.HOR
10rect_dsc.bg_grad.stops[0].color = lv.palette_main(lv.PALETTE.RED)
11rect_dsc.bg_grad.stops[1].color = lv.palette_main(lv.PALETTE.BLUE)
12rect_dsc.border_width = 2
13rect_dsc.border_opa = lv.OPA._90
14rect_dsc.border_color = lv.color_white()
15rect_dsc.shadow_width = 5
16rect_dsc.shadow_ofs_x = 5
17rect_dsc.shadow_ofs_y = 5
18
19label_dsc = lv.draw_label_dsc_t()
20label_dsc.init()
21label_dsc.color = lv.palette_main(lv.PALETTE.YELLOW)
22
23cbuf = bytearray(_CANVAS_WIDTH * _CANVAS_HEIGHT * 4)
24
25canvas = lv.canvas(lv.scr_act())
26canvas.set_buffer(cbuf, _CANVAS_WIDTH, _CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR)
27canvas.center()
28canvas.fill_bg(lv.palette_lighten(lv.PALETTE.GREY, 3), lv.OPA.COVER)
29
30canvas.draw_rect(70, 60, 100, 70, rect_dsc)
31canvas.draw_text(40, 20, 100, label_dsc, "Some text on text canvas")
32
33# Test the rotation. It requires another buffer where the original image is stored.
34# So copy the current image to buffer and rotate it to the canvas
35
36img = lv.img_dsc_t()
37img.data = cbuf[:]
38img.header.cf = lv.img.CF.TRUE_COLOR
39img.header.w = _CANVAS_WIDTH
40img.header.h = _CANVAS_HEIGHT
41
42canvas.fill_bg(lv.palette_lighten(lv.PALETTE.GREY, 3), lv.OPA.COVER)
43canvas.transform(img, 30, LV_IMG_ZOOM_NONE, 0, 0, _CANVAS_WIDTH // 2, _CANVAS_HEIGHT // 2, True)
44