mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-27 11:57:48 +08:00
examples(canvas): add canvas drawing examples
This commit is contained in:
@@ -11,3 +11,37 @@ Transparent Canvas with chroma keying
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_2
|
||||
:language: c
|
||||
|
||||
|
||||
Draw a rectangle to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_3
|
||||
:language: c
|
||||
|
||||
|
||||
Draw a label to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_4
|
||||
:language: c
|
||||
|
||||
|
||||
Draw an arc to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_5
|
||||
:language: c
|
||||
|
||||
|
||||
Draw an image to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_6
|
||||
:language: c
|
||||
|
||||
|
||||
Draw a line to the canvas
|
||||
""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
.. lv_example:: widgets/canvas/lv_example_canvas_7
|
||||
:language: c
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw a rectangle to the canvas
|
||||
*/
|
||||
void lv_example_canvas_3(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_rect_dsc_t dsc;
|
||||
lv_draw_rect_dsc_init(&dsc);
|
||||
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;
|
||||
lv_canvas_draw_rect(canvas, 10, 10, 30, 20, &dsc);
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_FONT_MONTSERRAT_18 && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw a text to the canvas
|
||||
*/
|
||||
void lv_example_canvas_4(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_label_dsc_t dsc;
|
||||
lv_draw_label_dsc_init(&dsc);
|
||||
dsc.color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.font = &lv_font_montserrat_18;
|
||||
dsc.decor = LV_TEXT_DECOR_UNDERLINE;
|
||||
|
||||
lv_canvas_draw_text(canvas, 10, 10, 30, &dsc, "Hello");
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw an arc to the canvas
|
||||
*/
|
||||
void lv_example_canvas_5(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_arc_dsc_t dsc;
|
||||
lv_draw_arc_dsc_init(&dsc);
|
||||
dsc.color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.width = 5;
|
||||
|
||||
lv_canvas_draw_arc(canvas, 25, 25, 15, 0, 220, &dsc);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,27 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS && LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw an image to the canvas
|
||||
*/
|
||||
void lv_example_canvas_6(void)
|
||||
{
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_img_dsc_t dsc;
|
||||
lv_draw_img_dsc_init(&dsc);
|
||||
|
||||
LV_IMG_DECLARE(img_star);
|
||||
lv_canvas_draw_img(canvas, 5, 5, &img_star, &dsc);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_CANVAS&& LV_BUILD_EXAMPLES
|
||||
|
||||
#define CANVAS_WIDTH 50
|
||||
#define CANVAS_HEIGHT 50
|
||||
|
||||
/**
|
||||
* Draw a line to the canvas
|
||||
*/
|
||||
void lv_example_canvas_7(void)
|
||||
{
|
||||
|
||||
/*Create a button to better see the transparency*/
|
||||
lv_btn_create(lv_scr_act());
|
||||
|
||||
/*Create a buffer for the canvas*/
|
||||
static uint8_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)];
|
||||
|
||||
/*Create a canvas and initialize its palette*/
|
||||
lv_obj_t * canvas = lv_canvas_create(lv_scr_act());
|
||||
lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR);
|
||||
lv_canvas_fill_bg(canvas, lv_color_hex3(0xccc), LV_OPA_COVER);
|
||||
lv_obj_center(canvas);
|
||||
|
||||
lv_draw_line_dsc_t dsc;
|
||||
lv_draw_line_dsc_init(&dsc);
|
||||
dsc.color = lv_palette_main(LV_PALETTE_RED);
|
||||
dsc.width = 4;
|
||||
dsc.round_end = 1;
|
||||
dsc.round_start = 1;
|
||||
|
||||
lv_point_t p[] = {{15, 15}, {35, 10}, {10, 40}};
|
||||
lv_canvas_draw_line(canvas, p, 3, &dsc);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user