1 /**
2 * @file lv_xml_slider_parser.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_xml_slider_parser.h"
10 #if LV_USE_XML
11
12 #include "../../../lvgl.h"
13 #include "../../../lvgl_private.h"
14
15 /*********************
16 * DEFINES
17 *********************/
18
19 /**********************
20 * TYPEDEFS
21 **********************/
22
23 /**********************
24 * STATIC PROTOTYPES
25 **********************/
26 static lv_slider_orientation_t orentation_text_to_enum_value(const char * txt);
27 static lv_slider_mode_t mode_text_to_enum_value(const char * txt);
28
29 /**********************
30 * STATIC VARIABLES
31 **********************/
32
33 /**********************
34 * MACROS
35 **********************/
36
37 /**********************
38 * GLOBAL FUNCTIONS
39 **********************/
40
lv_xml_slider_create(lv_xml_parser_state_t * state,const char ** attrs)41 void * lv_xml_slider_create(lv_xml_parser_state_t * state, const char ** attrs)
42 {
43 LV_UNUSED(attrs);
44
45 void * item = lv_slider_create(lv_xml_state_get_parent(state));
46 return item;
47 }
48
lv_xml_slider_apply(lv_xml_parser_state_t * state,const char ** attrs)49 void lv_xml_slider_apply(lv_xml_parser_state_t * state, const char ** attrs)
50 {
51 void * item = lv_xml_state_get_item(state);
52 lv_xml_obj_apply(state, attrs); /*Apply the common properties, e.g. width, height, styles flags etc*/
53
54 for(int i = 0; attrs[i]; i += 2) {
55 const char * name = attrs[i];
56 const char * value = attrs[i + 1];
57
58 if(lv_streq("value", name)) lv_slider_set_value(item, lv_xml_atoi(value), LV_ANIM_OFF);
59 if(lv_streq("left_value", name)) lv_slider_set_left_value(item, lv_xml_atoi(value), LV_ANIM_OFF);
60 if(lv_streq("orientation", name)) lv_slider_set_orientation(item, orentation_text_to_enum_value(value));
61 if(lv_streq("mode", name)) lv_slider_set_mode(item, mode_text_to_enum_value(value));
62 if(lv_streq("range_min", name)) lv_slider_set_range(item, lv_xml_atoi(value), lv_slider_get_max_value(item));
63 if(lv_streq("range_max", name)) lv_slider_set_range(item, lv_slider_get_min_value(item), lv_xml_atoi(value));
64 if(lv_streq("range", name)) {
65 char buf[64];
66 lv_strlcpy(buf, value, sizeof(buf));
67 char * buf_p = buf;
68 int32_t v1 = lv_xml_atoi(lv_xml_split_str(&buf_p, ' '));
69 int32_t v2 = lv_xml_atoi(buf_p);
70 lv_slider_set_range(item, v1, v2);
71 }
72 }
73 }
74
75 /**********************
76 * STATIC FUNCTIONS
77 **********************/
78
orentation_text_to_enum_value(const char * txt)79 static lv_slider_orientation_t orentation_text_to_enum_value(const char * txt)
80 {
81 if(lv_streq("auto", txt)) return LV_SLIDER_ORIENTATION_AUTO;
82 if(lv_streq("horizontal", txt)) return LV_SLIDER_ORIENTATION_HORIZONTAL;
83 if(lv_streq("vertical", txt)) return LV_SLIDER_ORIENTATION_VERTICAL;
84
85 LV_LOG_WARN("%s is an unknown value for slider's orientation", txt);
86 return 0; /*Return 0 in lack of a better option. */
87 }
88
mode_text_to_enum_value(const char * txt)89 static lv_slider_mode_t mode_text_to_enum_value(const char * txt)
90 {
91 if(lv_streq("normal", txt)) return LV_SLIDER_MODE_NORMAL;
92 if(lv_streq("range", txt)) return LV_SLIDER_MODE_RANGE;
93 if(lv_streq("symmetrical", txt)) return LV_SLIDER_MODE_SYMMETRICAL;
94
95 LV_LOG_WARN("%s is an unknown value for slider's mode", txt);
96 return 0; /*Return 0 in lack of a better option. */
97 }
98
99 #endif /* LV_USE_XML */
100