diff --git a/examples/assets/font/montserrat-18.fnt b/examples/assets/font/montserrat-18.fnt new file mode 100644 index 000000000..f483f470e Binary files /dev/null and b/examples/assets/font/montserrat-18.fnt differ diff --git a/examples/widgets/canvas/lv_example_canvas_3.py b/examples/widgets/canvas/lv_example_canvas_3.py new file mode 100644 index 000000000..d476ecd2d --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_3.py @@ -0,0 +1,31 @@ +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 +# +# Draw a rectangle to the canvas +# +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette*/ +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) + +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_rect_dsc_t() +dsc.init() + +dsc.bg_color = lv.palette_main(lv.PALETTE.RED) +dsc.border_color = lv.palette_main(lv.PALETTE.BLUE) +dsc.border_width = 3 +dsc.outline_color = lv.palette_main(lv.PALETTE.GREEN) +dsc.outline_width = 2 +dsc.outline_pad = 2 +dsc.outline_opa = lv.OPA._50 +dsc.radius = 5 +dsc.border_width = 3 +canvas.draw_rect(10, 10, 30, 20, dsc) + diff --git a/examples/widgets/canvas/lv_example_canvas_4.py b/examples/widgets/canvas/lv_example_canvas_4.py new file mode 100644 index 000000000..30439d8d2 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_4.py @@ -0,0 +1,44 @@ +import fs_driver + +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# +# Draw a text to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_label_dsc_t() +dsc.init() + +dsc.color = lv.palette_main(lv.PALETTE.RED) + +try: + dsc.font = lv_font_montserrat_18 +except: + # needed for dynamic font loading + fs_drv = lv.fs_drv_t() + fs_driver.fs_register(fs_drv, 'S') + + print("Loading font montserrat_18") + font_montserrat_18 = lv.font_load("S:../../assets/font/montserrat-18.fnt") + if not font_montserrat_18: + print("Font loading failed") + else: + dsc.font = font_montserrat_18 + +dsc.decor = lv.TEXT_DECOR.UNDERLINE +print('Printing "Hello"') +canvas.draw_text(10, 10, 30, dsc, "Hello") + + diff --git a/examples/widgets/canvas/lv_example_canvas_5.py b/examples/widgets/canvas/lv_example_canvas_5.py new file mode 100644 index 000000000..2bd9ce856 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_5.py @@ -0,0 +1,32 @@ +#!/opt/bin/lv_micropython -i +# Initialize + +import lvgl as lv +import display_driver +import fs_driver + +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# +# Draw an arc to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_arc_dsc_t() +dsc.init() +dsc.color = lv.palette_main(lv.PALETTE.RED) +dsc.width = 5 + +canvas.draw_arc(25, 25, 15, 0, 220, dsc) + diff --git a/examples/widgets/canvas/lv_example_canvas_6.py b/examples/widgets/canvas/lv_example_canvas_6.py new file mode 100644 index 000000000..d9de0fe2c --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_6.py @@ -0,0 +1,36 @@ +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# Create an image from the png file +try: + with open('../../assets/img_star.png','rb') as f: + png_data = f.read() +except: + print("Could not find star.png") + sys.exit() + +img_star_argb = lv.img_dsc_t({ + 'data_size': len(png_data), + 'data': png_data +}) + +# +# Draw an image to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_img_dsc_t() +dsc.init() + +canvas.draw_img(5, 5, img_star_argb, dsc) + diff --git a/examples/widgets/canvas/lv_example_canvas_7.py b/examples/widgets/canvas/lv_example_canvas_7.py new file mode 100644 index 000000000..ec12cc186 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_7.py @@ -0,0 +1,33 @@ +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +LV_COLOR_SIZE = 32 + +# +# Draw a line to the canvas +# + +# Create a buffer for the canvas +cbuf = bytearray((LV_COLOR_SIZE // 8) * CANVAS_WIDTH * CANVAS_HEIGHT) + +# Create a canvas and initialize its palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.fill_bg(lv.color_hex3(0xccc), lv.OPA.COVER) +canvas.center() + +dsc = lv.draw_line_dsc_t() +dsc.init() + +dsc.color = lv.palette_main(lv.PALETTE.RED) +dsc.width = 4 +dsc.round_end = 1 +dsc.round_start = 1 + +p = [ {"x":15,"y":15}, + {"x":35,"y":10}, + {"x":10,"y":40} ] + +canvas.draw_line(p, 3, dsc) + +