1 /**
2  * @file lv_xml_label_parser.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "lv_xml_label_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_label_long_mode_t long_mode_text_to_enum_value(const char * txt);
27 
28 /**********************
29  *  STATIC VARIABLES
30  **********************/
31 
32 /**********************
33  *      MACROS
34  **********************/
35 
36 /**********************
37  *   GLOBAL FUNCTIONS
38  **********************/
39 
lv_xml_label_create(lv_xml_parser_state_t * state,const char ** attrs)40 void * lv_xml_label_create(lv_xml_parser_state_t * state, const char ** attrs)
41 {
42     LV_UNUSED(attrs);
43     void * item = lv_label_create(lv_xml_state_get_parent(state));
44 
45     return item;
46 }
47 
lv_xml_label_apply(lv_xml_parser_state_t * state,const char ** attrs)48 void lv_xml_label_apply(lv_xml_parser_state_t * state, const char ** attrs)
49 {
50     void * item = lv_xml_state_get_item(state);
51 
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("text", name)) lv_label_set_text(item, value);
59         if(lv_streq("long_mode", name)) lv_label_set_long_mode(item, long_mode_text_to_enum_value(value));
60     }
61 }
62 
63 /**********************
64  *   STATIC FUNCTIONS
65  **********************/
66 
long_mode_text_to_enum_value(const char * txt)67 static lv_label_long_mode_t long_mode_text_to_enum_value(const char * txt)
68 {
69     if(lv_streq("wrap", txt)) return LV_LABEL_LONG_MODE_WRAP;
70     if(lv_streq("scroll", txt)) return LV_LABEL_LONG_MODE_SCROLL;
71 
72     LV_LOG_WARN("%s is an unknown value for label's long_mode", txt);
73     return 0; /*Return 0 in lack of a better option. */
74 }
75 
76 #endif /* LV_USE_XML */
77