mirror of
https://github.com/lvgl/lvgl.git
synced 2026-05-23 15:56:59 +08:00
feat(xml): add canvas and calendar support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
@@ -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*/
|
||||
@@ -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 */
|
||||
@@ -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*/
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 18 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -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);
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
+3
-15
@@ -10,24 +10,12 @@ Example
|
||||
<param name="month" type="int" help=""/>
|
||||
<param name="day" type="int" help=""/>
|
||||
</prop>
|
||||
<prop name="shown_date" help="Shown date">
|
||||
<prop name="month_shown" help="Shown date">
|
||||
<param name="year" type="int" help=""/>
|
||||
<param name="month" type="int" help=""/>
|
||||
<param name="day" type="int" help=""/>
|
||||
</prop>
|
||||
<prop name="shown_date" help="Shown date">
|
||||
<param name="year" type="int" help=""/>
|
||||
<param name="month" type="int" help=""/>
|
||||
<param name="day" type="int" help=""/>
|
||||
</prop>
|
||||
<prop name="day_names" help="set the names for the days">
|
||||
<param name="names" type="string[7]" help="the 7 day names as an array"/>
|
||||
</prop>
|
||||
<prop name="chinese_mode" help="">
|
||||
<param name="enable" type="bool" help=""/>
|
||||
</prop>
|
||||
<element name="header_arrow" access="explicit" help=""/>
|
||||
<element name="header_dropdown" access="explicit" help="">
|
||||
<element name="header_arrow" access="add" help=""/>
|
||||
<element name="header_dropdown" access="add" help="">
|
||||
<prop name="year_list">
|
||||
<param name="list" type="string" />
|
||||
</prop>
|
||||
|
||||
Reference in New Issue
Block a user