From a5350633084865df1cf6b938ae016eb834631bb4 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Wed, 22 Jan 2025 05:16:00 +0800 Subject: [PATCH] feat(xml): add support scale, span, roller and bar Also add some backward compatible API changes --- .../lv_demo_high_res_app_ev_charging.c | 8 +- demos/high_res/lv_demo_high_res_home.c | 8 +- demos/widgets/lv_demo_widgets.c | 21 +-- examples/others/xml/view.xml | 21 +-- examples/widgets/scale/lv_example_scale_2.c | 9 +- examples/widgets/scale/lv_example_scale_4.c | 9 +- examples/widgets/scale/lv_example_scale_5.c | 6 +- examples/widgets/slider/lv_example_slider_3.c | 2 +- examples/widgets/span/lv_example_span_1.c | 12 +- src/lv_api_map_v9_1.h | 10 +- src/misc/lv_style.c | 30 ++++ src/misc/lv_style.h | 15 ++ src/others/xml/lv_xml.c | 12 +- src/others/xml/lv_xml_utils.c | 5 +- src/others/xml/parsers/lv_xml_bar_parser.c | 111 +++++++++++++ src/others/xml/parsers/lv_xml_bar_parser.h | 40 +++++ src/others/xml/parsers/lv_xml_roller_parser.c | 108 +++++++++++++ src/others/xml/parsers/lv_xml_roller_parser.h | 40 +++++ src/others/xml/parsers/lv_xml_scale_parser.c | 135 ++++++++++++++++ src/others/xml/parsers/lv_xml_scale_parser.h | 41 +++++ src/others/xml/parsers/lv_xml_slider_parser.c | 19 ++- .../xml/parsers/lv_xml_spangroup_parser.c | 106 +++++++++++++ .../xml/parsers/lv_xml_spangroup_parser.h | 41 +++++ src/widgets/scale/lv_scale.c | 56 ++++++- src/widgets/scale/lv_scale.h | 37 ++++- src/widgets/scale/lv_scale_private.h | 18 ++- src/widgets/slider/lv_slider.c | 10 +- src/widgets/slider/lv_slider.h | 2 +- src/widgets/span/lv_span.c | 146 ++++++++++-------- src/widgets/span/lv_span.h | 50 +++++- src/widgets/span/lv_span_private.h | 2 - tests/ref_imgs/xml/gradients.png | Bin 35950 -> 36694 bytes tests/ref_imgs/xml/lv_bar.png | Bin 0 -> 3785 bytes tests/ref_imgs/xml/lv_roller.png | Bin 0 -> 3632 bytes tests/ref_imgs/xml/lv_scale.png | Bin 0 -> 9540 bytes tests/ref_imgs/xml/lv_spangroup.png | Bin 0 -> 8993 bytes tests/ref_imgs_vg_lite/xml/gradients.png | Bin 20248 -> 20835 bytes tests/ref_imgs_vg_lite/xml/lv_bar.png | Bin 0 -> 4364 bytes tests/ref_imgs_vg_lite/xml/lv_roller.png | Bin 0 -> 3680 bytes tests/ref_imgs_vg_lite/xml/lv_scale.png | Bin 0 -> 11135 bytes tests/ref_imgs_vg_lite/xml/lv_spangroup.png | Bin 0 -> 8656 bytes tests/src/test_cases/widgets/test_scale.c | 40 ++--- tests/src/test_cases/widgets/test_slider.c | 2 +- tests/src/test_cases/widgets/test_span.c | 92 +++++------ tests/src/test_cases/xml/test_xml_bar.c | 74 +++++++++ tests/src/test_cases/xml/test_xml_chart.c | 3 + tests/src/test_cases/xml/test_xml_roller.c | 36 +++++ tests/src/test_cases/xml/test_xml_scale.c | 53 +++++++ tests/src/test_cases/xml/test_xml_slider.c | 3 +- tests/src/test_cases/xml/test_xml_spangroup.c | 67 ++++++++ xmls/lv_bar.xml | 13 +- xmls/lv_dropdown.xml | 5 +- xmls/lv_roller.xml | 21 +++ xmls/lv_scale.xml | 45 ++---- xmls/lv_slider.xml | 5 + xmls/lv_spangroup.xml | 27 +--- 56 files changed, 1328 insertions(+), 288 deletions(-) create mode 100644 src/others/xml/parsers/lv_xml_bar_parser.c create mode 100644 src/others/xml/parsers/lv_xml_bar_parser.h create mode 100644 src/others/xml/parsers/lv_xml_roller_parser.c create mode 100644 src/others/xml/parsers/lv_xml_roller_parser.h create mode 100644 src/others/xml/parsers/lv_xml_scale_parser.c create mode 100644 src/others/xml/parsers/lv_xml_scale_parser.h create mode 100644 src/others/xml/parsers/lv_xml_spangroup_parser.c create mode 100644 src/others/xml/parsers/lv_xml_spangroup_parser.h create mode 100644 tests/ref_imgs/xml/lv_bar.png create mode 100644 tests/ref_imgs/xml/lv_roller.png create mode 100644 tests/ref_imgs/xml/lv_scale.png create mode 100644 tests/ref_imgs/xml/lv_spangroup.png create mode 100644 tests/ref_imgs_vg_lite/xml/lv_bar.png create mode 100644 tests/ref_imgs_vg_lite/xml/lv_roller.png create mode 100644 tests/ref_imgs_vg_lite/xml/lv_scale.png create mode 100644 tests/ref_imgs_vg_lite/xml/lv_spangroup.png create mode 100644 tests/src/test_cases/xml/test_xml_bar.c create mode 100644 tests/src/test_cases/xml/test_xml_roller.c create mode 100644 tests/src/test_cases/xml/test_xml_scale.c create mode 100644 tests/src/test_cases/xml/test_xml_spangroup.c create mode 100644 xmls/lv_roller.xml diff --git a/demos/high_res/lv_demo_high_res_app_ev_charging.c b/demos/high_res/lv_demo_high_res_app_ev_charging.c index 7d8d4eb54..7ebf8d8c6 100644 --- a/demos/high_res/lv_demo_high_res_app_ev_charging.c +++ b/demos/high_res/lv_demo_high_res_app_ev_charging.c @@ -283,9 +283,9 @@ static void create_widget1(lv_demo_high_res_ctx_t * c, lv_obj_t * widgets) lv_obj_t * total_spent_span = lv_spangroup_create(spent_box); lv_obj_add_style(total_spent_span, &c->fonts[FONT_LABEL_XS], 0); lv_obj_add_style(total_spent_span, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0); - lv_span_t * total_spent_amount = lv_spangroup_new_span(total_spent_span); + lv_span_t * total_spent_amount = lv_spangroup_add_span(total_spent_span); anim_state->spent_span_small = total_spent_amount; - lv_span_t * total_spent_label = lv_spangroup_new_span(total_spent_span); + lv_span_t * total_spent_label = lv_spangroup_add_span(total_spent_span); lv_span_set_text_static(total_spent_label, "Total spent"); lv_style_set_text_opa(&total_spent_label->style, LV_OPA_40); @@ -313,9 +313,9 @@ static void create_widget1(lv_demo_high_res_ctx_t * c, lv_obj_t * widgets) lv_obj_t * gas_equivalent_span = lv_spangroup_create(spent_box); lv_obj_add_style(gas_equivalent_span, &c->fonts[FONT_LABEL_XS], 0); lv_obj_add_style(gas_equivalent_span, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0); - lv_span_t * gas_equivalent_amount = lv_spangroup_new_span(gas_equivalent_span); + lv_span_t * gas_equivalent_amount = lv_spangroup_add_span(gas_equivalent_span); lv_span_set_text_static(gas_equivalent_amount, "$340 - "); - lv_span_t * gas_equivalent_label = lv_spangroup_new_span(gas_equivalent_span); + lv_span_t * gas_equivalent_label = lv_spangroup_add_span(gas_equivalent_span); lv_span_set_text_static(gas_equivalent_label, "Gas Equivalent"); lv_style_set_text_opa(&gas_equivalent_label->style, LV_OPA_40); } diff --git a/demos/high_res/lv_demo_high_res_home.c b/demos/high_res/lv_demo_high_res_home.c index 529cbe44b..a9a6d5679 100644 --- a/demos/high_res/lv_demo_high_res_home.c +++ b/demos/high_res/lv_demo_high_res_home.c @@ -91,16 +91,16 @@ void lv_demo_high_res_home(lv_obj_t * base_obj) lv_obj_t * date = lv_spangroup_create(date_and_time); lv_obj_add_style(date, &c->fonts[FONT_HEADING_MD], 0); lv_obj_add_style(date, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0); - lv_spangroup_new_span(date); - lv_span_t * day_and_month = lv_spangroup_new_span(date); + lv_spangroup_add_span(date); + lv_span_t * day_and_month = lv_spangroup_add_span(date); lv_subject_add_observer_obj(&c->th, theme_observer_accent_span_cb, date, day_and_month); lv_subject_add_observer_obj(&c->subject_groups.date.group, date_observer_cb, date, c); lv_obj_t * time = lv_spangroup_create(date_and_time); lv_obj_add_style(time, &c->fonts[FONT_HEADING_XXL], 0); lv_obj_add_style(time, &c->styles[STYLE_COLOR_BASE][STYLE_TYPE_TEXT], 0); - lv_spangroup_new_span(time); - lv_span_t * minute = lv_spangroup_new_span(time); + lv_spangroup_add_span(time); + lv_span_t * minute = lv_spangroup_add_span(time); lv_subject_add_observer_obj(&c->th, theme_observer_accent_span_cb, time, minute); lv_subject_add_observer_obj(&c->subject_groups.time.group, time_observer_cb, time, c); diff --git a/demos/widgets/lv_demo_widgets.c b/demos/widgets/lv_demo_widgets.c index b405af795..986493fb0 100644 --- a/demos/widgets/lv_demo_widgets.c +++ b/demos/widgets/lv_demo_widgets.c @@ -829,21 +829,16 @@ static void analytics_create(lv_obj_t * parent) lv_scale_section_t * section; section = lv_scale_add_section(scale3); - lv_scale_section_set_range(section, 0, 20); - lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section1_main_style); - lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section1_indicator_style); - lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section1_tick_style); - section = lv_scale_add_section(scale3); - lv_scale_section_set_range(section, 20, 40); - lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section2_main_style); - lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section2_indicator_style); - lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section2_tick_style); + lv_scale_set_section_range(scale3, section, 0, 20); + lv_scale_set_section_style_main(scale3, section, &scale3_section2_main_style); + lv_scale_set_section_style_indicator(scale3, section, &scale3_section2_indicator_style); + lv_scale_set_section_style_items(scale3, section, &scale3_section2_tick_style); section = lv_scale_add_section(scale3); - lv_scale_section_set_range(section, 40, 60); - lv_scale_section_set_style(section, LV_PART_MAIN, &scale3_section3_main_style); - lv_scale_section_set_style(section, LV_PART_INDICATOR, &scale3_section3_indicator_style); - lv_scale_section_set_style(section, LV_PART_ITEMS, &scale3_section3_tick_style); + lv_scale_set_section_range(scale3, section, 40, 60); + lv_scale_set_section_style_main(scale3, section, &scale3_section3_main_style); + lv_scale_set_section_style_indicator(scale3, section, &scale3_section3_indicator_style); + lv_scale_set_section_style_items(scale3, section, &scale3_section3_tick_style); LV_IMAGE_DECLARE(img_demo_widgets_needle); scale3_needle = lv_image_create(scale3); diff --git a/examples/others/xml/view.xml b/examples/others/xml/view.xml index 388a83c61..89390df2b 100644 --- a/examples/others/xml/view.xml +++ b/examples/others/xml/view.xml @@ -1,24 +1,17 @@ - + -