feat(NemaGFX): add vector draw task support (#8938)

This commit is contained in:
Liam Howatt
2025-10-02 16:26:54 +02:00
committed by GitHub
parent b97b928b21
commit 75efb0a12e
11 changed files with 303 additions and 19 deletions
+2
View File
@@ -0,0 +1,2 @@
<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>

After

Width:  |  Height:  |  Size: 139 B

+12 -1
View File
@@ -1,6 +1,17 @@
Load and render SVG data
---------------------------------------
------------------------
.. lv_example:: libs/svg/lv_example_svg_1
:language: c
Load and render SVG data from a file
------------------------------------
.. lv_example:: libs/svg/lv_example_svg_2
:language: c
Load and render SVG data in a draw event
----------------------------------------
.. lv_example:: libs/svg/lv_example_svg_3
:language: c
+2
View File
@@ -26,6 +26,8 @@ extern "C" {
* GLOBAL PROTOTYPES
**********************/
void lv_example_svg_1(void);
void lv_example_svg_2(void);
void lv_example_svg_3(void);
/**********************
* MACROS
+13 -13
View File
@@ -3,22 +3,22 @@
#if LV_USE_SVG && LV_USE_VECTOR_GRAPHIC
/**
* Load an SVG data
* Load an SVG from 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);
static const 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>";
static lv_image_dsc_t svg_dsc;
svg_dsc.header.magic = LV_IMAGE_HEADER_MAGIC;
svg_dsc.header.w = 450;
svg_dsc.header.h = 150;
svg_dsc.data_size = sizeof(svg_data) - 1;
svg_dsc.data = (const uint8_t *) svg_data;
lv_obj_t * svg = lv_image_create(lv_screen_active());
lv_image_set_src(svg, &svg_dsc);
}
#else
+26
View File
@@ -0,0 +1,26 @@
#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_SVG && LV_USE_VECTOR_GRAPHIC
/**
* Load an SVG from a file
*/
void lv_example_svg_2(void)
{
lv_obj_t * svg = lv_image_create(lv_screen_active());
lv_image_set_src(svg, "A:lvgl/examples/assets/circle.svg");
}
#else
void lv_example_svg_2(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
+36
View File
@@ -0,0 +1,36 @@
#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES
#if LV_USE_SVG && LV_USE_VECTOR_GRAPHIC
/**
* Draw SVG data in a draw event
*/
static void event_cb(lv_event_t * e)
{
static const 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_3(void)
{
lv_obj_add_event_cb(lv_screen_active(), event_cb, LV_EVENT_DRAW_MAIN, NULL);
}
#else
void lv_example_svg_3(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