feat(libs): add SVG rendering support (#6845)
Signed-off-by: zhangjipeng <zhangjipeng@xiaomi.com> Co-authored-by: zhangjipeng <zhangjipeng@xiaomi.com>
This commit is contained in:
@@ -25,6 +25,7 @@ extern "C" {
|
||||
#include "tjpgd/lv_example_tjpgd.h"
|
||||
#include "libjpeg_turbo/lv_example_libjpeg_turbo.h"
|
||||
#include "tiny_ttf/lv_example_tiny_ttf.h"
|
||||
#include "svg/lv_example_svg.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
|
||||
6
examples/libs/svg/index.rst
Normal file
6
examples/libs/svg/index.rst
Normal file
@@ -0,0 +1,6 @@
|
||||
Load and render SVG data
|
||||
---------------------------------------
|
||||
|
||||
.. lv_example:: libs/svg/lv_example_svg_1
|
||||
:language: c
|
||||
|
||||
38
examples/libs/svg/lv_example_svg.h
Normal file
38
examples/libs/svg/lv_example_svg.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @file lv_example_svg.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_EXAMPLE_SVG_H
|
||||
#define LV_EXAMPLE_SVG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
void lv_example_svg_1(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*LV_EXAMPLE_SVG_H*/
|
||||
36
examples/libs/svg/lv_example_svg_1.c
Normal file
36
examples/libs/svg/lv_example_svg_1.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_BUILD_EXAMPLES
|
||||
#if LV_USE_SVG && LV_USE_VECTOR_GRAPHIC
|
||||
|
||||
/**
|
||||
* Load an SVG data
|
||||
*/
|
||||
static void event_cb(lv_event_t * e)
|
||||
{
|
||||
static char svg_data[] = "<svg width=\"12cm\" height=\"4cm\" viewBox=\"0 0 1200 400\">"
|
||||
"<circle cx=\"600\" cy=\"200\" r=\"100\" fill=\"red\" stroke=\"blue\" stroke-width=\"10\"/></svg>";
|
||||
|
||||
lv_layer_t * layer = lv_event_get_layer(e);
|
||||
lv_svg_node_t * svg = lv_svg_load_data(svg_data, sizeof(svg_data) / sizeof(char));
|
||||
lv_draw_svg(layer, svg);
|
||||
lv_svg_node_delete(svg);
|
||||
}
|
||||
|
||||
void lv_example_svg_1(void)
|
||||
{
|
||||
lv_obj_add_event_cb(lv_screen_active(), event_cb, LV_EVENT_DRAW_MAIN, NULL);
|
||||
}
|
||||
#else
|
||||
|
||||
void lv_example_svg_1(void)
|
||||
{
|
||||
/*TODO
|
||||
*fallback for online examples*/
|
||||
|
||||
lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(label, "SVG is not enabled");
|
||||
lv_obj_center(label);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user