1 #include "../../lv_examples.h"
2 #if LV_BUILD_EXAMPLES && LV_USE_XML
3
lv_example_xml_1(void)4 void lv_example_xml_1(void)
5 {
6 /*A red button created from builti-in LVGL widgets
7 *It has an API parameter too to change its text.*/
8 const char * red_button_xml =
9 "<component>"
10 " <api>"
11 " <prop name=\"button_text\" type=\"string\" default=\"None\"/>"
12 " </api>"
13 " <view extends=\"lv_button\" radius=\"0\" style_bg_color=\"0xa91500\">"
14 " <lv_label text=\"$button_text\" align=\"center\"/>"
15 " </view>"
16 "</component>";
17
18 /*The card is just an lv_obj where a label and two red buttons are used.
19 * Its API allow setting a title (label test) and the action (the text of a button)*/
20 const char * card_xml =
21 "<component>"
22 " <api>"
23 " <prop name=\"title\" type=\"string\" default=\"Hello world\"/>"
24 " <prop name=\"action\" type=\"string\"/>"
25 " </api>"
26 " <view width=\"200\" height=\"content\">"
27 " <lv_label text=\"$title\" align=\"top_mid\"/>"
28 " <red_button y=\"20\" align=\"top_left\" button_text=\"Cancel\"/>"
29 " <red_button y=\"20\" align=\"top_right\" button_text=\"$action\"/>"
30 " </view>"
31 "</component>";
32
33 /* Motor card is a special case of a card where the title and action are already set*/
34 const char * motor_card_xml =
35 "<component>"
36 " <view extends=\"card\" title=\"Motor start?\" action=\"Start\">"
37 " </view>"
38 "</component>";
39
40 /*Register all the custom components*/
41 lv_xml_component_register_from_data("red_button", red_button_xml);
42 lv_xml_component_register_from_data("card", card_xml);
43 lv_xml_component_register_from_data("motor_card", motor_card_xml);
44
45 lv_obj_t * card;
46 /*Create a card with the default values*/
47 card = lv_xml_create(lv_screen_active(), "card", NULL);
48
49 /*Create a motor card too. The returned value can be adjusted freely*/
50 card = lv_xml_create(lv_screen_active(), "motor_card", NULL);
51 lv_obj_set_y(card, 90);
52
53 /*Pass properties to a card*/
54 const char * attrs[] = {
55 "y", "180",
56 "action", "Apply",
57 "title", "New title",
58 NULL, NULL,
59 };
60 card = lv_xml_create(lv_screen_active(), "card", attrs);
61
62 }
63 #endif
64