1 /**
2  * @file lv_xml_base_parser.c
3  *
4  */
5 
6 /*********************
7  *      INCLUDES
8  *********************/
9 #include "../../lvgl.h"
10 #if LV_USE_XML
11 
12 #include "lv_xml_base_types.h"
13 #include "lv_xml_private.h"
14 #include "lv_xml_parser.h"
15 #include "lv_xml_style.h"
16 #include "lv_xml_component_private.h"
17 
18 /*********************
19  *      DEFINES
20  *********************/
21 
22 /**********************
23  *      TYPEDEFS
24  **********************/
25 
26 /**********************
27  *  STATIC PROTOTYPES
28  **********************/
29 
30 /**********************
31  *  STATIC VARIABLES
32  **********************/
33 
34 /**********************
35  *      MACROS
36  **********************/
37 
38 /**********************
39  *   GLOBAL FUNCTIONS
40  **********************/
41 
lv_xml_to_size(const char * txt)42 int32_t lv_xml_to_size(const char * txt)
43 {
44     if(lv_streq(txt, "content")) return LV_SIZE_CONTENT;
45 
46     int32_t v = lv_xml_atoi(txt);
47     if(txt[lv_strlen(txt) - 1] == '%') return lv_pct(v);
48     else return v;
49 }
50 
lv_xml_align_to_enum(const char * txt)51 lv_align_t lv_xml_align_to_enum(const char * txt)
52 {
53     if(lv_streq("top_left", txt)) return LV_ALIGN_TOP_LEFT;
54     if(lv_streq("top_mid", txt)) return LV_ALIGN_TOP_MID;
55     if(lv_streq("top_right", txt)) return LV_ALIGN_TOP_RIGHT;
56     if(lv_streq("bottom_left", txt)) return LV_ALIGN_BOTTOM_LEFT;
57     if(lv_streq("bottom_mid", txt)) return LV_ALIGN_BOTTOM_MID;
58     if(lv_streq("bottom_right", txt)) return LV_ALIGN_BOTTOM_RIGHT;
59     if(lv_streq("right_mid", txt)) return LV_ALIGN_RIGHT_MID;
60     if(lv_streq("left_mid", txt)) return LV_ALIGN_LEFT_MID;
61     if(lv_streq("center", txt)) return LV_ALIGN_CENTER;
62 
63     LV_LOG_WARN("%s is an unknown value for align", txt);
64     return 0; /*Return 0 in lack of a better option. */
65 }
66 
lv_xml_dir_to_enum(const char * txt)67 lv_dir_t lv_xml_dir_to_enum(const char * txt)
68 {
69     if(lv_streq("none", txt)) return LV_DIR_NONE;
70     if(lv_streq("top", txt)) return LV_DIR_TOP;
71     if(lv_streq("bottom", txt)) return LV_DIR_BOTTOM;
72     if(lv_streq("left", txt)) return LV_DIR_LEFT;
73     if(lv_streq("right", txt)) return LV_DIR_RIGHT;
74     if(lv_streq("all", txt)) return LV_DIR_ALL;
75 
76     LV_LOG_WARN("%s is an unknown value for dir", txt);
77     return 0; /*Return 0 in lack of a better option. */
78 }
79 
lv_xml_border_side_to_enum(const char * txt)80 lv_border_side_t lv_xml_border_side_to_enum(const char * txt)
81 {
82     if(lv_streq("none", txt)) return LV_BORDER_SIDE_NONE;
83     if(lv_streq("top", txt)) return LV_BORDER_SIDE_TOP;
84     if(lv_streq("bottom", txt)) return LV_BORDER_SIDE_BOTTOM;
85     if(lv_streq("left", txt)) return LV_BORDER_SIDE_LEFT;
86     if(lv_streq("right", txt)) return LV_BORDER_SIDE_RIGHT;
87     if(lv_streq("full", txt)) return LV_BORDER_SIDE_FULL;
88 
89     LV_LOG_WARN("%s is an unknown value for border_side", txt);
90     return 0; /*Return 0 in lack of a better option. */
91 }
92 
lv_xml_grad_dir_to_enum(const char * txt)93 lv_grad_dir_t lv_xml_grad_dir_to_enum(const char * txt)
94 {
95     if(lv_streq("none", txt)) return LV_GRAD_DIR_NONE;
96     if(lv_streq("hor", txt)) return LV_GRAD_DIR_HOR;
97     if(lv_streq("ver", txt)) return LV_GRAD_DIR_VER;
98 
99     LV_LOG_WARN("%s is an unknown value for grad_dir", txt);
100     return 0; /*Return 0 in lack of a better option. */
101 }
102 
lv_xml_base_dir_to_enum(const char * txt)103 lv_base_dir_t lv_xml_base_dir_to_enum(const char * txt)
104 {
105     if(lv_streq("auto", txt)) return LV_BASE_DIR_AUTO;
106     if(lv_streq("ltr", txt)) return LV_BASE_DIR_LTR;
107     if(lv_streq("rtl", txt)) return LV_BASE_DIR_RTL;
108 
109     LV_LOG_WARN("%s is an unknown value for base_dir", txt);
110     return 0; /*Return 0 in lack of a better option. */
111 }
112 
lv_xml_text_align_to_enum(const char * txt)113 lv_text_align_t lv_xml_text_align_to_enum(const char * txt)
114 {
115     if(lv_streq("left", txt)) return LV_TEXT_ALIGN_LEFT;
116     if(lv_streq("right", txt)) return LV_TEXT_ALIGN_RIGHT;
117     if(lv_streq("center", txt)) return LV_TEXT_ALIGN_CENTER;
118     if(lv_streq("auto", txt)) return LV_TEXT_ALIGN_AUTO;
119 
120     LV_LOG_WARN("%s is an unknown value for text_align", txt);
121     return 0; /*Return 0 in lack of a better option. */
122 }
123 
lv_xml_text_decor_to_enum(const char * txt)124 lv_text_decor_t lv_xml_text_decor_to_enum(const char * txt)
125 {
126     if(lv_streq("none", txt)) return LV_TEXT_DECOR_NONE;
127     if(lv_streq("underline", txt)) return LV_TEXT_DECOR_UNDERLINE;
128     if(lv_streq("strikethrough", txt)) return LV_TEXT_DECOR_STRIKETHROUGH;
129 
130     LV_LOG_WARN("%s is an unknown value for text_decor", txt);
131     return 0; /*Return 0 in lack of a better option. */
132 }
133 
lv_xml_flex_flow_to_enum(const char * txt)134 lv_flex_flow_t lv_xml_flex_flow_to_enum(const char * txt)
135 {
136     if(lv_streq("column", txt)) return LV_FLEX_FLOW_COLUMN;
137     if(lv_streq("column_reverse", txt)) return LV_FLEX_FLOW_COLUMN_REVERSE;
138     if(lv_streq("column_wrap", txt)) return LV_FLEX_FLOW_COLUMN_WRAP;
139     if(lv_streq("column_wrap_reverse", txt)) return LV_FLEX_FLOW_COLUMN_WRAP_REVERSE;
140     if(lv_streq("row", txt)) return LV_FLEX_FLOW_ROW;
141     if(lv_streq("row_reverse", txt)) return LV_FLEX_FLOW_ROW_REVERSE;
142     if(lv_streq("row_wrap", txt)) return LV_FLEX_FLOW_ROW_WRAP;
143     if(lv_streq("row_wrap_reverse", txt)) return LV_FLEX_FLOW_ROW_WRAP_REVERSE;
144 
145     LV_LOG_WARN("%s is an unknown value for flex_flow", txt);
146     return 0; /*Return 0 in lack of a better option. */
147 }
148 
lv_xml_flex_align_to_enum(const char * txt)149 lv_flex_align_t lv_xml_flex_align_to_enum(const char * txt)
150 {
151     if(lv_streq("center", txt)) return LV_FLEX_ALIGN_CENTER;
152     if(lv_streq("end", txt)) return LV_FLEX_ALIGN_END;
153     if(lv_streq("start", txt)) return LV_FLEX_ALIGN_START;
154     if(lv_streq("space_around", txt)) return LV_FLEX_ALIGN_SPACE_AROUND;
155     if(lv_streq("space_between", txt)) return LV_FLEX_ALIGN_SPACE_BETWEEN;
156     if(lv_streq("space_evenly", txt)) return LV_FLEX_ALIGN_SPACE_EVENLY;
157 
158     LV_LOG_WARN("%s is an unknown value for flex_align", txt);
159     return 0; /*Return 0 in lack of a better option. */
160 }
161 
lv_xml_grid_align_to_enum(const char * txt)162 lv_grid_align_t lv_xml_grid_align_to_enum(const char * txt)
163 {
164     if(lv_streq("center", txt)) return LV_GRID_ALIGN_CENTER;
165     if(lv_streq("end", txt)) return LV_GRID_ALIGN_END;
166     if(lv_streq("start", txt)) return LV_GRID_ALIGN_START;
167     if(lv_streq("stretch", txt)) return LV_GRID_ALIGN_STRETCH;
168     if(lv_streq("space_around", txt)) return LV_GRID_ALIGN_SPACE_AROUND;
169     if(lv_streq("space_between", txt)) return LV_GRID_ALIGN_SPACE_BETWEEN;
170     if(lv_streq("space_evenly", txt)) return LV_GRID_ALIGN_SPACE_EVENLY;
171 
172     LV_LOG_WARN("%s is an unknown value for grid_align", txt);
173     return 0; /*Return 0 in lack of a better option. */
174 }
175 
176 
lv_xml_layout_to_enum(const char * txt)177 lv_layout_t lv_xml_layout_to_enum(const char * txt)
178 {
179     if(lv_streq("none", txt)) return LV_LAYOUT_NONE;
180     if(lv_streq("flex", txt)) return LV_LAYOUT_FLEX;
181     if(lv_streq("grid", txt)) return LV_LAYOUT_GRID;
182 
183     LV_LOG_WARN("%s is an unknown value for layout", txt);
184     return 0; /*Return 0 in lack of a better option. */
185 }
186 
lv_xml_blend_mode_to_enum(const char * txt)187 lv_blend_mode_t lv_xml_blend_mode_to_enum(const char * txt)
188 {
189     if(lv_streq("normal", txt)) return LV_BLEND_MODE_NORMAL;
190     if(lv_streq("additive", txt)) return LV_BLEND_MODE_ADDITIVE;
191     if(lv_streq("subtractive", txt)) return LV_BLEND_MODE_SUBTRACTIVE;
192     if(lv_streq("multiply", txt)) return LV_BLEND_MODE_MULTIPLY;
193 
194     LV_LOG_WARN("%s is an unknown value for blend_mode", txt);
195     return 0; /*Return 0 in lack of a better option. */
196 }
197 /**********************
198  *   STATIC FUNCTIONS
199  **********************/
200 
201 #endif /* LV_USE_XML */
202