add some code

This commit is contained in:
2025-09-05 13:25:11 +08:00
parent 9ff0a99e7a
commit 3cf1229a85
8911 changed files with 2535396 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
Load components at runtime
--------------------------
.. lv_example:: others/xml/lv_example_xml_1
:language: c
.. lv_example:: others/xml/lv_example_xml_2
:language: c

View File

@@ -0,0 +1,39 @@
/**
* @file lv_example_xml.h
*
*/
#ifndef LV_EXAMPLE_XML_H
#define LV_EXAMPLE_XML_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_example_xml_1(void);
void lv_example_xml_2(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*LV_EXAMPLE_XML_H*/

View File

@@ -0,0 +1,63 @@
#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_XML
void lv_example_xml_1(void)
{
/*A red button created from builti-in LVGL widgets
*It has an API parameter too to change its text.*/
const char * red_button_xml =
"<component>"
" <api>"
" <prop name=\"button_text\" type=\"string\" default=\"None\"/>"
" </api>"
" <view extends=\"lv_button\" radius=\"0\" style_bg_color=\"0xa91500\">"
" <lv_label text=\"$button_text\" align=\"center\"/>"
" </view>"
"</component>";
/*The card is just an lv_obj where a label and two red buttons are used.
* Its API allow setting a title (label test) and the action (the text of a button)*/
const char * card_xml =
"<component>"
" <api>"
" <prop name=\"title\" type=\"string\" default=\"Hello world\"/>"
" <prop name=\"action\" type=\"string\"/>"
" </api>"
" <view width=\"200\" height=\"content\">"
" <lv_label text=\"$title\" align=\"top_mid\"/>"
" <red_button y=\"20\" align=\"top_left\" button_text=\"Cancel\"/>"
" <red_button y=\"20\" align=\"top_right\" button_text=\"$action\"/>"
" </view>"
"</component>";
/* Motor card is a special case of a card where the title and action are already set*/
const char * motor_card_xml =
"<component>"
" <view extends=\"card\" title=\"Motor start?\" action=\"Start\">"
" </view>"
"</component>";
/*Register all the custom components*/
lv_xml_component_register_from_data("red_button", red_button_xml);
lv_xml_component_register_from_data("card", card_xml);
lv_xml_component_register_from_data("motor_card", motor_card_xml);
lv_obj_t * card;
/*Create a card with the default values*/
card = (lv_obj_t *) lv_xml_create(lv_screen_active(), "card", NULL);
/*Create a motor card too. The returned value can be adjusted freely*/
card = (lv_obj_t *) lv_xml_create(lv_screen_active(), "motor_card", NULL);
lv_obj_set_y(card, 90);
/*Pass properties to a card*/
const char * attrs[] = {
"y", "180",
"action", "Apply",
"title", "New title",
NULL, NULL,
};
card = (lv_obj_t *) lv_xml_create(lv_screen_active(), "card", attrs);
}
#endif

View File

@@ -0,0 +1,46 @@
#include "../../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_XML
void lv_example_xml_2(void)
{
lv_result_t res;
res = lv_xml_component_register_from_file("A:lvgl/examples/others/xml/my_h3.xml");
if(res != LV_RESULT_OK) {
lv_obj_t * label = lv_label_create(lv_screen_active());
lv_label_set_text(label, "Couldn't open the XML files.");
lv_obj_center(label);
return;
}
lv_xml_component_register_from_file("A:lvgl/examples/others/xml/my_card.xml");
lv_xml_component_register_from_file("A:lvgl/examples/others/xml/my_button.xml");
lv_xml_component_register_from_file("A:lvgl/examples/others/xml/view.xml");
lv_xml_register_font(NULL, "lv_montserrat_18", &lv_font_montserrat_18);
lv_obj_t * obj = (lv_obj_t *) lv_xml_create(lv_screen_active(), "view", NULL);
lv_obj_set_pos(obj, 10, 10);
const char * my_button_attrs[] = {
"x", "10",
"y", "-10",
"align", "bottom_left",
"btn_text", "New button",
NULL, NULL,
};
lv_xml_component_unregister("my_button");
lv_xml_create(lv_screen_active(), "my_button", my_button_attrs);
const char * slider_attrs[] = {
"x", "200",
"y", "-15",
"align", "bottom_left",
"value", "30",
NULL, NULL,
};
lv_obj_t * slider = (lv_obj_t *) lv_xml_create(lv_screen_active(), "lv_slider", slider_attrs);
lv_obj_set_width(slider, 100);
}
#endif

View File

@@ -0,0 +1,15 @@
<component>
<consts>
<px name="size" value="100"/>
<color name="orange" value="0xffa020"/>
</consts>
<api>
<prop name="btn_text" type="string"/>
</api>
<view extends="lv_button" width="#size">
<my_h3 text="$btn_text" align="center" color="#orange"/>
</view>
</component>

View File

@@ -0,0 +1,31 @@
<component>
<gradients>
<horizontal_gradient name="grad1" >
<stop color="#ff0000" frac="30%" opa="100%"/>
<stop color="#00ff00" frac="200" opa="100%"/>
</horizontal_gradient>
</gradients>
<consts>
<px name="size" value="100%"/>
</consts>
<api>
<prop name="title" type="string" default="No title"/>
<prop name="action" type="string" default="No action"/>
<prop name="bg_color" type="color" default="0xcccccc"/>
<prop name="btn_rel_style" type="style" />
<prop name="btn_pr_style" type="style" />
</api>
<styles>
<style name="gray" bg_grad="grad1"/>
<style name="blue" bg_color="0x0000ff"/>
</styles>
<view extends="lv_obj" style_radius="3" width="#size" height="content" styles="gray" style_bg_color="$bg_color" >
<lv_label text="$title" align="left_mid"/>
<my_button styles="$btn_rel_style $btn_pr_style:pressed" btn_text="$action" align="right_mid"/>
</view>
</component>

View File

@@ -0,0 +1,12 @@
<component>
<api>
<prop name="color" type="color" default="0x000000"/>
<prop name="style" type="style"/>
</api>
<view extends="lv_label"
style_text_color="$color"
styles="$style"
style_text_font="lv_montserrat_18">
</view>
</component>

View File

@@ -0,0 +1,28 @@
<component>
<consts>
<color name="light_blue" value="0xbbbbff"/>
<color name="dark_blue" value="0x000080"/>
</consts>
<styles>
<style name="btn_style" bg_color="#dark_blue" bg_opa="150"/>
<style name="btn_pr_style" bg_opa="255"/>
<style name="red_border" border_color="0xff0000"></style>
</styles>
<view extends="lv_obj" name="main" width="280" height="content" style_bg_color="#light_blue">
<lv_label text="Hello"/>
<my_card title="Card 1" name="card1"
y="0"
styles="red_border"
btn_rel_style="btn_style"
btn_pr_style="btn_pr_style"/>
<my_card y="85"
bg_color="0xffaaaa"
action="Apply"
btn_rel_style="btn_style"
btn_pr_style="btn_pr_style"/>
</view>
</component>