From fc5939dcff72e1bd5430e3c403ee0c1392503afb Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 22 Nov 2024 10:46:13 +0100 Subject: [PATCH] feat(xml): add the basics of declarative XML support --- Kconfig | 5 +- docs/details/other-components/index.rst | 1 + docs/details/other-components/xml.rst | 301 + examples/others/lv_example_others.h | 1 + examples/others/xml/index.rst | 5 + examples/others/xml/lv_example_xml.h | 38 + examples/others/xml/lv_example_xml_1.c | 37 + examples/others/xml/my_button.xml | 15 + examples/others/xml/my_card.xml | 23 + examples/others/xml/my_h3.xml | 12 + examples/others/xml/view.xml | 25 + lv_conf_template.h | 5 +- lvgl.h | 2 + lvgl_private.h | 1 + scripts/code-format.cfg | 1 + src/libs/expat/add_lvgl_if.sh | 13 + src/libs/expat/ascii.h | 129 + src/libs/expat/asciitab.h | 72 + src/libs/expat/expat.h | 1081 +++ src/libs/expat/expat_config.h | 151 + src/libs/expat/expat_external.h | 171 + src/libs/expat/iasciitab.h | 73 + src/libs/expat/internal.h | 182 + src/libs/expat/latin1tab.h | 72 + src/libs/expat/nametab.h | 142 + src/libs/expat/siphash.h | 398 + src/libs/expat/utf8tab.h | 72 + src/libs/expat/winconfig.h | 54 + src/libs/expat/xmlparse.c | 8567 +++++++++++++++++ src/libs/expat/xmlrole.c | 1261 +++ src/libs/expat/xmlrole.h | 148 + src/libs/expat/xmltok.c | 1678 ++++ src/libs/expat/xmltok.h | 327 + src/libs/expat/xmltok_impl.c | 1825 ++++ src/libs/expat/xmltok_impl.h | 80 + src/libs/expat/xmltok_ns.c | 128 + src/lv_conf_internal.h | 11 +- src/lv_init.c | 7 +- src/misc/lv_types.h | 5 + src/others/xml/lv_xml.c | 389 + src/others/xml/lv_xml.h | 57 + src/others/xml/lv_xml_base_types.c | 111 + src/others/xml/lv_xml_base_types.h | 76 + src/others/xml/lv_xml_component.c | 306 + src/others/xml/lv_xml_component.h | 78 + src/others/xml/lv_xml_component_private.h | 58 + src/others/xml/lv_xml_parser.c | 98 + src/others/xml/lv_xml_parser.h | 84 + src/others/xml/lv_xml_private.h | 58 + src/others/xml/lv_xml_style.c | 202 + src/others/xml/lv_xml_style.h | 91 + src/others/xml/lv_xml_utils.c | 237 + src/others/xml/lv_xml_utils.h | 50 + src/others/xml/lv_xml_widget.c | 78 + src/others/xml/lv_xml_widget.h | 57 + src/others/xml/parsers/lv_xml_button_parser.c | 59 + src/others/xml/parsers/lv_xml_button_parser.h | 41 + src/others/xml/parsers/lv_xml_chart_parser.c | 145 + src/others/xml/parsers/lv_xml_chart_parser.h | 43 + src/others/xml/parsers/lv_xml_image_parser.c | 112 + src/others/xml/parsers/lv_xml_image_parser.h | 43 + src/others/xml/parsers/lv_xml_label_parser.c | 76 + src/others/xml/parsers/lv_xml_label_parser.h | 41 + src/others/xml/parsers/lv_xml_obj_parser.c | 89 + src/others/xml/parsers/lv_xml_obj_parser.h | 41 + src/others/xml/parsers/lv_xml_slider_parser.c | 99 + src/others/xml/parsers/lv_xml_slider_parser.h | 40 + .../xml/parsers/lv_xml_tabview_parser.c | 109 + .../xml/parsers/lv_xml_tabview_parser.h | 44 + src/stdlib/lv_string.h | 11 + tests/ref_imgs/xml/complex_1.png | Bin 0 -> 11154 bytes tests/ref_imgs/xml/component_create_1.png | Bin 0 -> 3937 bytes tests/ref_imgs/xml/consts_1.png | Bin 0 -> 2808 bytes tests/ref_imgs/xml/image_and_font_1.png | Bin 0 -> 9693 bytes tests/ref_imgs/xml/lv_slider.png | Bin 0 -> 5010 bytes tests/ref_imgs/xml/nested_1.png | Bin 0 -> 10919 bytes tests/ref_imgs/xml/params_1.png | Bin 0 -> 5000 bytes tests/ref_imgs/xml/styles_1.png | Bin 0 -> 4701 bytes tests/ref_imgs/xml/widget_create_1.png | Bin 0 -> 3880 bytes tests/ref_imgs_vg_lite/xml/complex_1.png | Bin 0 -> 12155 bytes .../xml/component_create_1.png | Bin 0 -> 4481 bytes tests/ref_imgs_vg_lite/xml/consts_1.png | Bin 0 -> 2779 bytes .../ref_imgs_vg_lite/xml/image_and_font_1.png | Bin 0 -> 5232 bytes tests/ref_imgs_vg_lite/xml/lv_slider.png | Bin 0 -> 5679 bytes tests/ref_imgs_vg_lite/xml/nested_1.png | Bin 0 -> 11209 bytes tests/ref_imgs_vg_lite/xml/params_1.png | Bin 0 -> 5027 bytes tests/ref_imgs_vg_lite/xml/styles_1.png | Bin 0 -> 5198 bytes .../ref_imgs_vg_lite/xml/widget_create_1.png | Bin 0 -> 4315 bytes tests/src/lv_test_conf_full.h | 1 + tests/src/test_assets/lv_example_xml.h | 38 + tests/src/test_assets/xml/my_button.xml | 15 + tests/src/test_assets/xml/my_card.xml | 23 + tests/src/test_assets/xml/my_h3.xml | 10 + tests/src/test_assets/xml/view.xml | 25 + tests/src/test_cases/xml/test_xml_general.c | 348 + tests/src/test_cases/xml/test_xml_slider.c | 75 + xmls/globals.xml | 45 + xmls/lv_animimg.xml | 18 + xmls/lv_arc.xml | 32 + xmls/lv_bar.xml | 38 + xmls/lv_button.xml | 11 + xmls/lv_buttonmatrix.xml | 46 + xmls/lv_calendar.xml | 36 + xmls/lv_canvas.xml | 10 + xmls/lv_chart.xml | 66 + xmls/lv_checkbox.xml | 12 + xmls/lv_dropdown.xml | 24 + xmls/lv_label.xml | 27 + xmls/lv_obj.xml | 71 + xmls/lv_scale.xml | 61 + xmls/lv_slider.xml | 27 + xmls/lv_spangroup.xml | 46 + xmls/lv_table.xml | 50 + xmls/lv_tabview.xml | 24 + 114 files changed, 21316 insertions(+), 5 deletions(-) create mode 100644 docs/details/other-components/xml.rst create mode 100644 examples/others/xml/index.rst create mode 100644 examples/others/xml/lv_example_xml.h create mode 100644 examples/others/xml/lv_example_xml_1.c create mode 100644 examples/others/xml/my_button.xml create mode 100644 examples/others/xml/my_card.xml create mode 100644 examples/others/xml/my_h3.xml create mode 100644 examples/others/xml/view.xml create mode 100755 src/libs/expat/add_lvgl_if.sh create mode 100644 src/libs/expat/ascii.h create mode 100644 src/libs/expat/asciitab.h create mode 100644 src/libs/expat/expat.h create mode 100644 src/libs/expat/expat_config.h create mode 100644 src/libs/expat/expat_external.h create mode 100644 src/libs/expat/iasciitab.h create mode 100644 src/libs/expat/internal.h create mode 100644 src/libs/expat/latin1tab.h create mode 100644 src/libs/expat/nametab.h create mode 100644 src/libs/expat/siphash.h create mode 100644 src/libs/expat/utf8tab.h create mode 100644 src/libs/expat/winconfig.h create mode 100644 src/libs/expat/xmlparse.c create mode 100644 src/libs/expat/xmlrole.c create mode 100644 src/libs/expat/xmlrole.h create mode 100644 src/libs/expat/xmltok.c create mode 100644 src/libs/expat/xmltok.h create mode 100644 src/libs/expat/xmltok_impl.c create mode 100644 src/libs/expat/xmltok_impl.h create mode 100644 src/libs/expat/xmltok_ns.c create mode 100644 src/others/xml/lv_xml.c create mode 100644 src/others/xml/lv_xml.h create mode 100644 src/others/xml/lv_xml_base_types.c create mode 100644 src/others/xml/lv_xml_base_types.h create mode 100644 src/others/xml/lv_xml_component.c create mode 100644 src/others/xml/lv_xml_component.h create mode 100644 src/others/xml/lv_xml_component_private.h create mode 100644 src/others/xml/lv_xml_parser.c create mode 100644 src/others/xml/lv_xml_parser.h create mode 100644 src/others/xml/lv_xml_private.h create mode 100644 src/others/xml/lv_xml_style.c create mode 100644 src/others/xml/lv_xml_style.h create mode 100644 src/others/xml/lv_xml_utils.c create mode 100644 src/others/xml/lv_xml_utils.h create mode 100644 src/others/xml/lv_xml_widget.c create mode 100644 src/others/xml/lv_xml_widget.h create mode 100644 src/others/xml/parsers/lv_xml_button_parser.c create mode 100644 src/others/xml/parsers/lv_xml_button_parser.h create mode 100644 src/others/xml/parsers/lv_xml_chart_parser.c create mode 100644 src/others/xml/parsers/lv_xml_chart_parser.h create mode 100644 src/others/xml/parsers/lv_xml_image_parser.c create mode 100644 src/others/xml/parsers/lv_xml_image_parser.h create mode 100644 src/others/xml/parsers/lv_xml_label_parser.c create mode 100644 src/others/xml/parsers/lv_xml_label_parser.h create mode 100644 src/others/xml/parsers/lv_xml_obj_parser.c create mode 100644 src/others/xml/parsers/lv_xml_obj_parser.h create mode 100644 src/others/xml/parsers/lv_xml_slider_parser.c create mode 100644 src/others/xml/parsers/lv_xml_slider_parser.h create mode 100644 src/others/xml/parsers/lv_xml_tabview_parser.c create mode 100644 src/others/xml/parsers/lv_xml_tabview_parser.h create mode 100644 tests/ref_imgs/xml/complex_1.png create mode 100644 tests/ref_imgs/xml/component_create_1.png create mode 100644 tests/ref_imgs/xml/consts_1.png create mode 100644 tests/ref_imgs/xml/image_and_font_1.png create mode 100644 tests/ref_imgs/xml/lv_slider.png create mode 100644 tests/ref_imgs/xml/nested_1.png create mode 100644 tests/ref_imgs/xml/params_1.png create mode 100644 tests/ref_imgs/xml/styles_1.png create mode 100644 tests/ref_imgs/xml/widget_create_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/complex_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/component_create_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/consts_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/image_and_font_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/lv_slider.png create mode 100644 tests/ref_imgs_vg_lite/xml/nested_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/params_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/styles_1.png create mode 100644 tests/ref_imgs_vg_lite/xml/widget_create_1.png create mode 100644 tests/src/test_assets/lv_example_xml.h create mode 100644 tests/src/test_assets/xml/my_button.xml create mode 100644 tests/src/test_assets/xml/my_card.xml create mode 100644 tests/src/test_assets/xml/my_h3.xml create mode 100644 tests/src/test_assets/xml/view.xml create mode 100644 tests/src/test_cases/xml/test_xml_general.c create mode 100644 tests/src/test_cases/xml/test_xml_slider.c create mode 100644 xmls/globals.xml create mode 100644 xmls/lv_animimg.xml create mode 100644 xmls/lv_arc.xml create mode 100644 xmls/lv_bar.xml create mode 100644 xmls/lv_button.xml create mode 100644 xmls/lv_buttonmatrix.xml create mode 100644 xmls/lv_calendar.xml create mode 100644 xmls/lv_canvas.xml create mode 100644 xmls/lv_chart.xml create mode 100644 xmls/lv_checkbox.xml create mode 100644 xmls/lv_dropdown.xml create mode 100644 xmls/lv_label.xml create mode 100644 xmls/lv_obj.xml create mode 100644 xmls/lv_scale.xml create mode 100644 xmls/lv_slider.xml create mode 100644 xmls/lv_spangroup.xml create mode 100644 xmls/lv_table.xml create mode 100644 xmls/lv_tabview.xml diff --git a/Kconfig b/Kconfig index 903a2dce1..d274fcc97 100644 --- a/Kconfig +++ b/Kconfig @@ -1390,7 +1390,7 @@ menu "LVGL configuration" default n help You won't be able to open URLs after enabling this feature. - Note that FFmpeg image decoder will always use lvgl file system. + Note that FFmpeg image decoder will always use lvgl file system. endmenu menu "Others" @@ -1591,7 +1591,8 @@ menu "LVGL configuration" int "Font manager name max length" depends on LV_USE_FONT_MANAGER default 32 - + config LV_USE_XML + bool "Enable loading XML UIs runtime" config LVGL_VERSION_MAJOR int default 9 # LVGL_VERSION_MAJOR diff --git a/docs/details/other-components/index.rst b/docs/details/other-components/index.rst index 769703559..45789cd15 100644 --- a/docs/details/other-components/index.rst +++ b/docs/details/other-components/index.rst @@ -18,3 +18,4 @@ Other Components obj_property observer snapshot + xml diff --git a/docs/details/other-components/xml.rst b/docs/details/other-components/xml.rst new file mode 100644 index 000000000..1937beb74 --- /dev/null +++ b/docs/details/other-components/xml.rst @@ -0,0 +1,301 @@ +.. _xml: + +==================== +XML - Declarative UI +==================== + +Introduction +------------ + +LVGL is capable of loading UI elements written in XML. +Although still under development, the basics are already functional, serving as a preview. + +This declarative language serves as the backend for LVGL's UI editor (currently under development), +which enables faster and more maintainable UI implementation. + +Note that, the UI editor is not required to utilize LVGL's XML loading capabilities. + +Describing the UI in XML in a declarative manner offers several advantages: + +- XML files can be loaded at runtime (e.g., from an SD card) to change the application build. +- XML is simpler to write than C, enabling people with different skill sets to create LVGL UIs. +- XML is textual data, making it easy to parse and manipulate with scripts. +- XML can be used to generate LVGL code in any language. +- XML helps to separate the view from the logic. + +Currently supported features: + +- Load XML components at runtime from file or data +- Nest components and widgets any deep +- Dynamically create instances of XML components in C +- Register images and font that can be accessed by name later in the XMLs +- Constants are working for widget and style properties +- Parameters can be defined and passed and used for components +- Basic built in widgets (label, slider, bar, button, etc) +- Style sheets and local styles that can be assigned to parts and states support the basic style properties + +Limitations: + +- Only basic widgets are supported with limited functionality. +- Only a few style properties are supported. +- Events are not supported yet. +- Animations are not supported yet. +- Subjects are not supported yet. +- The documentation is not complete yet. + +Main Concept +~~~~~~~~~~~~ + +It's important to distinguish between widgets and components: + +Widgets are the core building blocks of the UI and are not meant to be loaded at runtime +but rather compiled into the application. The main characteristics of widgets are: + +- Similar to LVGL's built-in widgets. +- Built from classes. +- Have a large API with set/get/add/etc. functions. +- Support "internal widgets" (e.g., tabview's tabs, dropdown's list). +- Have custom and complex logic inside. +- Cannot be loaded from XML at runtime because custom code cannot be loaded. + +Components are built from other components and widgets and can be loaded at runtime. +The main characteristics of components are: + +- Built from widgets or other components. +- Can be used for styling widgets. +- Can contain widgets or other components. +- Cannot have custom C code. +- Can be loaded from XML at runtime as they describe only the visuals. + +Components +---------- + +Overview +~~~~~~~~ + +In light of the above, only components can be loaded from XML. +An example of a ``my_button`` component looks like this: + +.. code-block:: xml + + + + + + + + + + + + +