diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c
index 3851fe0290..0d3b068373 100644
--- a/demos/widgets/lv_demo_widgets.c
+++ b/demos/widgets/lv_demo_widgets.c
@@ -1323,7 +1323,7 @@ static void birthday_event_cb(lv_event_t * e)
lv_obj_align(calendar, LV_ALIGN_CENTER, 0, 30);
lv_obj_add_event_cb(calendar, calendar_event_cb, LV_EVENT_ALL, ta);
- lv_calendar_header_dropdown_create(calendar);
+ lv_calendar_add_header_dropdown(calendar);
}
}
}
diff --git a/docs/src/details/widgets/calendar.rst b/docs/src/details/widgets/calendar.rst
index 7f849d9550..e5447428dc 100644
--- a/docs/src/details/widgets/calendar.rst
+++ b/docs/src/details/widgets/calendar.rst
@@ -154,14 +154,14 @@ the API of the headers has been changed.**
Arrow buttons
-------------
-:cpp:expr:`lv_calendar_header_arrow_create(calendar)` creates a header that
+:cpp:expr:`lv_calendar_add_header_arrow(calendar)` creates a header that
contains a left and right arrow on the sides and text between the arrows showing the
current year and month.
Drop-down
---------
-:cpp:expr:`lv_calendar_header_dropdown_create(calendar)` creates a header that
+:cpp:expr:`lv_calendar_add_header_dropdown(calendar)` creates a header that
contains 2 Drop-Drown List Widgets for the year and month.
.. _lv_calendar_example:
diff --git a/examples/widgets/calendar/lv_example_calendar_1.c b/examples/widgets/calendar/lv_example_calendar_1.c
index 7abc876c7b..35d0068348 100644
--- a/examples/widgets/calendar/lv_example_calendar_1.c
+++ b/examples/widgets/calendar/lv_example_calendar_1.c
@@ -41,9 +41,9 @@ void lv_example_calendar_1(void)
lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3);
#if LV_USE_CALENDAR_HEADER_DROPDOWN
- lv_calendar_header_dropdown_create(calendar);
+ lv_calendar_add_header_dropdown(calendar);
#elif LV_USE_CALENDAR_HEADER_ARROW
- lv_calendar_header_arrow_create(calendar);
+ lv_calendar_add_header_arrow(calendar);
#endif
}
diff --git a/examples/widgets/calendar/lv_example_calendar_2.c b/examples/widgets/calendar/lv_example_calendar_2.c
index 17aa511f8c..5b26b96d4e 100644
--- a/examples/widgets/calendar/lv_example_calendar_2.c
+++ b/examples/widgets/calendar/lv_example_calendar_2.c
@@ -11,9 +11,9 @@ void lv_example_calendar_2(void)
lv_calendar_set_month_shown(calendar, 2024, 03);
#if LV_USE_CALENDAR_HEADER_DROPDOWN
- lv_calendar_header_dropdown_create(calendar);
+ lv_calendar_add_header_dropdown(calendar);
#elif LV_USE_CALENDAR_HEADER_ARROW
- lv_calendar_header_arrow_create(calendar);
+ lv_calendar_add_header_arrow(calendar);
#endif
lv_calendar_set_chinese_mode(calendar, true);
diff --git a/src/lv_api_map_v9_1.h b/src/lv_api_map_v9_1.h
index 8a55c00352..162101365b 100644
--- a/src/lv_api_map_v9_1.h
+++ b/src/lv_api_map_v9_1.h
@@ -119,6 +119,9 @@ extern "C" {
#define lv_slider_set_left_value lv_slider_set_start_value
+#define lv_calendar_header_arrow_create lv_calendar_add_header_arrow
+#define lv_calendar_header_dropdown_create lv_calendar_add_header_dropdown
+
#ifdef __cplusplus
} /*extern "C"*/
#endif
diff --git a/src/others/xml/lv_xml.c b/src/others/xml/lv_xml.c
index 1986c9ee3d..6a8918ce25 100644
--- a/src/others/xml/lv_xml.c
+++ b/src/others/xml/lv_xml.c
@@ -37,6 +37,8 @@
#include "parsers/lv_xml_keyboard_parser.h"
#include "parsers/lv_xml_arc_parser.h"
#include "parsers/lv_xml_checkbox_parser.h"
+#include "parsers/lv_xml_canvas_parser.h"
+#include "parsers/lv_xml_calendar_parser.h"
#include "parsers/lv_xml_event_parser.h"
#include "../../libs/expat/expat.h"
#include "../../draw/lv_draw_image.h"
@@ -101,6 +103,12 @@ void lv_xml_init(void)
lv_xml_widget_register("lv_keyboard", lv_xml_keyboard_create, lv_xml_keyboard_apply);
lv_xml_widget_register("lv_arc", lv_xml_arc_create, lv_xml_arc_apply);
lv_xml_widget_register("lv_checkbox", lv_xml_checkbox_create, lv_xml_checkbox_apply);
+ lv_xml_widget_register("lv_canvas", lv_xml_canvas_create, lv_xml_canvas_apply);
+ lv_xml_widget_register("lv_calendar", lv_xml_calendar_create, lv_xml_calendar_apply);
+ lv_xml_widget_register("lv_calendar-header_arrow", lv_xml_calendar_header_arrow_create,
+ lv_xml_calendar_header_arrow_apply);
+ lv_xml_widget_register("lv_calendar-header_dropdown", lv_xml_calendar_header_dropdown_create,
+ lv_xml_calendar_header_dropdown_apply);
lv_xml_widget_register("lv_event-call_function", lv_xml_event_call_function_create, lv_xml_event_call_function_apply);
}
diff --git a/src/others/xml/parsers/lv_xml_calendar_parser.c b/src/others/xml/parsers/lv_xml_calendar_parser.c
new file mode 100644
index 0000000000..4af1a9ff4e
--- /dev/null
+++ b/src/others/xml/parsers/lv_xml_calendar_parser.c
@@ -0,0 +1,104 @@
+/**
+ * @file lv_xml_calendar_parser.c
+ *
+ */
+
+/*********************
+ * INCLUDES
+ *********************/
+#include "lv_xml_calendar_parser.h"
+#if LV_USE_XML
+
+#include "../../../lvgl.h"
+#include "../../../lvgl_private.h"
+
+/*********************
+ * DEFINES
+ *********************/
+
+/**********************
+ * TYPEDEFS
+ **********************/
+
+/**********************
+ * STATIC PROTOTYPES
+ **********************/
+
+/**********************
+ * STATIC VARIABLES
+ **********************/
+
+/**********************
+ * MACROS
+ **********************/
+
+/**********************
+ * GLOBAL FUNCTIONS
+ **********************/
+
+void * lv_xml_calendar_create(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ LV_UNUSED(attrs);
+ void * item = lv_calendar_create(lv_xml_state_get_parent(state));
+
+ return item;
+}
+
+
+void lv_xml_calendar_apply(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ void * item = lv_xml_state_get_item(state);
+
+ lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
+
+ for(int i = 0; attrs[i]; i += 2) {
+ const char * name = attrs[i];
+ const char * value = attrs[i + 1];
+
+ if(lv_streq("today_date", name)) {
+ const char * bufp = value;
+ int32_t y = lv_xml_atoi_split(&bufp, ' ');
+ int32_t m = lv_xml_atoi_split(&bufp, ' ');
+ int32_t d = lv_xml_atoi_split(&bufp, ' ');
+ lv_calendar_set_today_date(item, y, m, d);
+ }
+ else if(lv_streq("shown_month", name)) {
+ const char * bufp = value;
+ int32_t y = lv_xml_atoi_split(&bufp, ' ');
+ int32_t m = lv_xml_atoi_split(&bufp, ' ');
+ lv_calendar_set_month_shown(item, y, m);
+ }
+ }
+}
+
+void * lv_xml_calendar_header_dropdown_create(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ LV_UNUSED(attrs);
+ void * item = lv_calendar_add_header_dropdown(lv_xml_state_get_parent(state));
+ return item;
+}
+
+void lv_xml_calendar_header_dropdown_apply(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
+}
+
+void * lv_xml_calendar_header_arrow_create(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ LV_UNUSED(attrs);
+ void * item = lv_calendar_add_header_arrow(lv_xml_state_get_parent(state));
+
+ return item;
+}
+
+void lv_xml_calendar_header_arrow_apply(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
+}
+
+
+/**********************
+ * STATIC FUNCTIONS
+ **********************/
+
+#endif /* LV_USE_XML */
diff --git a/src/others/xml/parsers/lv_xml_calendar_parser.h b/src/others/xml/parsers/lv_xml_calendar_parser.h
new file mode 100644
index 0000000000..881101ecb4
--- /dev/null
+++ b/src/others/xml/parsers/lv_xml_calendar_parser.h
@@ -0,0 +1,43 @@
+/**
+ * @file lv_xml_calendar_parser.h
+ *
+ */
+
+#ifndef LV_CALENDAR_XML_PARSER_H
+#define LV_CALENDAR_XML_PARSER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************
+ * INCLUDES
+ *********************/
+#include "../lv_xml.h"
+#if LV_USE_XML
+
+/**********************
+ * TYPEDEFS
+ **********************/
+
+/**********************
+ * GLOBAL PROTOTYPES
+ **********************/
+
+void * lv_xml_calendar_create(lv_xml_parser_state_t * state, const char ** attrs);
+void lv_xml_calendar_apply(lv_xml_parser_state_t * state, const char ** attrs);
+void * lv_xml_calendar_header_arrow_create(lv_xml_parser_state_t * state, const char ** attrs);
+void lv_xml_calendar_header_arrow_apply(lv_xml_parser_state_t * state, const char ** attrs);
+void * lv_xml_calendar_header_dropdown_create(lv_xml_parser_state_t * state, const char ** attrs);
+void lv_xml_calendar_header_dropdown_apply(lv_xml_parser_state_t * state, const char ** attrs);
+
+/**********************
+ * MACROS
+ **********************/
+#endif /* LV_USE_XML */
+
+#ifdef __cplusplus
+} /*extern "C"*/
+#endif
+
+#endif /*LV_CHART_XML_PARSE_H*/
diff --git a/src/others/xml/parsers/lv_xml_canvas_parser.c b/src/others/xml/parsers/lv_xml_canvas_parser.c
new file mode 100644
index 0000000000..dde37c6232
--- /dev/null
+++ b/src/others/xml/parsers/lv_xml_canvas_parser.c
@@ -0,0 +1,59 @@
+/**
+ * @file lv_xml_canvas_parser.c
+ *
+ */
+
+/*********************
+ * INCLUDES
+ *********************/
+
+#include "lv_xml_canvas_parser.h"
+#if LV_USE_XML
+#include "../../../lvgl.h"
+#include "../../../lvgl_private.h"
+
+
+/*********************
+ * DEFINES
+ *********************/
+
+/**********************
+ * TYPEDEFS
+ **********************/
+
+/**********************
+ * STATIC PROTOTYPES
+ **********************/
+
+/**********************
+ * STATIC VARIABLES
+ **********************/
+
+/**********************
+ * MACROS
+ **********************/
+
+/**********************
+ * GLOBAL FUNCTIONS
+ **********************/
+
+void * lv_xml_canvas_create(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ LV_UNUSED(attrs);
+
+ void * item = lv_canvas_create(lv_xml_state_get_parent(state));
+
+ return item;
+}
+
+void lv_xml_canvas_apply(lv_xml_parser_state_t * state, const char ** attrs)
+{
+ /*Apply the common properties, e.g. width, height, styles flags etc*/
+ lv_xml_obj_apply(state, attrs);
+}
+
+/**********************
+ * STATIC FUNCTIONS
+ **********************/
+
+#endif /* LV_USE_XML */
diff --git a/src/others/xml/parsers/lv_xml_canvas_parser.h b/src/others/xml/parsers/lv_xml_canvas_parser.h
new file mode 100644
index 0000000000..040478e659
--- /dev/null
+++ b/src/others/xml/parsers/lv_xml_canvas_parser.h
@@ -0,0 +1,41 @@
+/**
+ * @file lv_xml_canvas_parser.h
+ *
+ */
+
+#ifndef LV_CANVAS_XML_PARSER_H
+#define LV_CANVAS_XML_PARSER_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************
+ * INCLUDES
+ *********************/
+#include "../lv_xml.h"
+#if LV_USE_XML
+
+/**********************
+ * TYPEDEFS
+ **********************/
+
+/**********************
+ * GLOBAL PROTOTYPES
+ **********************/
+
+void * lv_xml_canvas_create(lv_xml_parser_state_t * state, const char ** attrs);
+void lv_xml_canvas_apply(lv_xml_parser_state_t * state, const char ** attrs);
+
+
+/**********************
+ * MACROS
+ **********************/
+
+#endif /* LV_USE_XML */
+
+#ifdef __cplusplus
+} /*extern "C"*/
+#endif
+
+#endif /*LV_BUTTON_XML_PARSE_H*/
diff --git a/src/widgets/calendar/lv_calendar_header_arrow.c b/src/widgets/calendar/lv_calendar_header_arrow.c
index 7234fd62f9..caf0dd52d5 100644
--- a/src/widgets/calendar/lv_calendar_header_arrow.c
+++ b/src/widgets/calendar/lv_calendar_header_arrow.c
@@ -53,7 +53,7 @@ static const char * month_names_def[12] = LV_CALENDAR_DEFAULT_MONTH_NAMES;
* GLOBAL FUNCTIONS
**********************/
-lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent)
+lv_obj_t * lv_calendar_add_header_arrow(lv_obj_t * parent)
{
lv_obj_t * obj = lv_obj_class_create_obj(&lv_calendar_header_arrow_class, parent);
lv_obj_class_init_obj(obj);
diff --git a/src/widgets/calendar/lv_calendar_header_arrow.h b/src/widgets/calendar/lv_calendar_header_arrow.h
index a04b355cc7..54f4fbed7b 100644
--- a/src/widgets/calendar/lv_calendar_header_arrow.h
+++ b/src/widgets/calendar/lv_calendar_header_arrow.h
@@ -34,7 +34,7 @@ LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_calendar_header_arrow_cl
* @param parent pointer to a calendar object.
* @return the created header
*/
-lv_obj_t * lv_calendar_header_arrow_create(lv_obj_t * parent);
+lv_obj_t * lv_calendar_add_header_arrow(lv_obj_t * parent);
/**********************
* MACROS
diff --git a/src/widgets/calendar/lv_calendar_header_dropdown.c b/src/widgets/calendar/lv_calendar_header_dropdown.c
index b70fbe9175..2052981827 100644
--- a/src/widgets/calendar/lv_calendar_header_dropdown.c
+++ b/src/widgets/calendar/lv_calendar_header_dropdown.c
@@ -61,7 +61,7 @@ static const char * year_list = {
* GLOBAL FUNCTIONS
**********************/
-lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent)
+lv_obj_t * lv_calendar_add_header_dropdown(lv_obj_t * parent)
{
lv_obj_t * obj = lv_obj_class_create_obj(&lv_calendar_header_dropdown_class, parent);
lv_obj_class_init_obj(obj);
diff --git a/src/widgets/calendar/lv_calendar_header_dropdown.h b/src/widgets/calendar/lv_calendar_header_dropdown.h
index 1ca87762e2..13b01304ef 100644
--- a/src/widgets/calendar/lv_calendar_header_dropdown.h
+++ b/src/widgets/calendar/lv_calendar_header_dropdown.h
@@ -38,7 +38,7 @@ LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_calendar_header_dropdown
* @param parent pointer to a calendar object.
* @return the created header
*/
-lv_obj_t * lv_calendar_header_dropdown_create(lv_obj_t * parent);
+lv_obj_t * lv_calendar_add_header_dropdown(lv_obj_t * parent);
/**
* Sets a custom calendar year list
diff --git a/tests/ref_imgs/xml/lv_calendar.png b/tests/ref_imgs/xml/lv_calendar.png
new file mode 100644
index 0000000000..d336c68379
Binary files /dev/null and b/tests/ref_imgs/xml/lv_calendar.png differ
diff --git a/tests/ref_imgs/xml/lv_canvas.png b/tests/ref_imgs/xml/lv_canvas.png
new file mode 100644
index 0000000000..7b9b1b42b9
Binary files /dev/null and b/tests/ref_imgs/xml/lv_canvas.png differ
diff --git a/tests/ref_imgs_vg_lite/xml/lv_calendar.png b/tests/ref_imgs_vg_lite/xml/lv_calendar.png
new file mode 100644
index 0000000000..5daae3e663
Binary files /dev/null and b/tests/ref_imgs_vg_lite/xml/lv_calendar.png differ
diff --git a/tests/ref_imgs_vg_lite/xml/lv_canvas.png b/tests/ref_imgs_vg_lite/xml/lv_canvas.png
new file mode 100644
index 0000000000..7b9b1b42b9
Binary files /dev/null and b/tests/ref_imgs_vg_lite/xml/lv_canvas.png differ
diff --git a/tests/src/test_cases/widgets/test_calendar.c b/tests/src/test_cases/widgets/test_calendar.c
index 2aba76358c..e671b38fd5 100644
--- a/tests/src/test_cases/widgets/test_calendar.c
+++ b/tests/src/test_cases/widgets/test_calendar.c
@@ -164,7 +164,7 @@ void test_calendar_get_highlighted_dates_num(void)
void test_calendar_header_dropdown_create_gui(void)
{
- lv_calendar_header_dropdown_create(g_calendar);
+ lv_calendar_add_header_dropdown(g_calendar);
lv_calendar_set_month_shown(g_calendar, 2022, 9);
@@ -173,7 +173,7 @@ void test_calendar_header_dropdown_create_gui(void)
void test_calendar_header_arrow_create_gui(void)
{
- lv_calendar_header_arrow_create(g_calendar);
+ lv_calendar_add_header_arrow(g_calendar);
lv_calendar_set_month_shown(g_calendar, 2022, 10); // Use October to avoid month name sliding
@@ -213,7 +213,7 @@ void test_calendar_custom_year_list(void)
{
lv_obj_t * calendar = lv_calendar_create(lv_screen_active());
- lv_calendar_header_dropdown_create(calendar);
+ lv_calendar_add_header_dropdown(calendar);
const char * years = "2024\n2023\n2022\n2021\n2020\n2019";
lv_calendar_header_dropdown_set_year_list(calendar, years);
diff --git a/tests/src/test_cases/xml/test_xml_calendar.c b/tests/src/test_cases/xml/test_xml_calendar.c
new file mode 100644
index 0000000000..ff279fc29c
--- /dev/null
+++ b/tests/src/test_cases/xml/test_xml_calendar.c
@@ -0,0 +1,42 @@
+
+#if LV_BUILD_TEST
+#include "../lvgl.h"
+
+#include "unity/unity.h"
+
+void setUp(void)
+{
+ /* Function run before every test */
+}
+
+void tearDown(void)
+{
+ /* Function run after every test */
+ lv_obj_clean(lv_screen_active());
+}
+
+void test_xml_calendar_with_attrs(void)
+{
+ lv_obj_t * scr = lv_screen_active();
+
+ const char * calendar_attrs[] = {
+ "width", "200",
+ "height", "200",
+ "x", "10",
+ "y", "10",
+ "today_date", "2025 05 06",
+ "shown_month", "2025 05",
+ NULL, NULL,
+ };
+ lv_obj_t * calendar;
+ calendar = lv_xml_create(scr, "lv_calendar", calendar_attrs);
+ lv_xml_create(calendar, "lv_calendar-header_arrow", NULL);
+
+ calendar = lv_xml_create(scr, "lv_calendar", calendar_attrs);
+ lv_obj_set_x(calendar, 250);
+ lv_xml_create(calendar, "lv_calendar-header_dropdown", NULL);
+
+ TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_calendar.png");
+}
+
+#endif
diff --git a/tests/src/test_cases/xml/test_xml_canvas.c b/tests/src/test_cases/xml/test_xml_canvas.c
new file mode 100644
index 0000000000..451e231992
--- /dev/null
+++ b/tests/src/test_cases/xml/test_xml_canvas.c
@@ -0,0 +1,39 @@
+#if LV_BUILD_TEST
+#include "../lvgl.h"
+
+#include "unity/unity.h"
+
+void setUp(void)
+{
+ /* Function run before every test */
+}
+
+void tearDown(void)
+{
+ /* Function run after every test */
+ lv_obj_clean(lv_screen_active());
+}
+
+void test_xml_canvas_with_attrs(void)
+{
+ lv_obj_t * scr = lv_screen_active();
+
+ const char * canvas1_attrs[] = {
+ "name", "c1",
+ "x", "10",
+ "y", "10",
+ NULL, NULL,
+ };
+
+ lv_xml_create(scr, "lv_canvas", canvas1_attrs);
+
+ lv_obj_t * c1 = lv_obj_find_by_name(NULL, "c1");
+ TEST_ASSERT_NOT_NULL(c1);
+ lv_draw_buf_t * draw_buf = lv_draw_buf_create(100, 100, LV_COLOR_FORMAT_XRGB8888, LV_STRIDE_AUTO);
+ lv_canvas_set_draw_buf(c1, draw_buf);
+ lv_canvas_fill_bg(c1, lv_color_hex3(0x234), LV_OPA_COVER);
+ TEST_ASSERT_EQUAL_SCREENSHOT("xml/lv_canvas.png");
+ lv_draw_buf_destroy(draw_buf);
+}
+
+#endif
diff --git a/xmls/lv_calendar.xml b/xmls/lv_calendar.xml
index 7afca8a293..cae4fd3a46 100644
--- a/xmls/lv_calendar.xml
+++ b/xmls/lv_calendar.xml
@@ -10,24 +10,12 @@ Example
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+