1 /**
2  * @file lv_xml_style.h
3  *
4  */
5 
6 #ifndef LV_XML_STYLE_H
7 #define LV_XML_STYLE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../../misc/lv_types.h"
17 #include "../../misc/lv_style.h"
18 #include "../../core/lv_obj_style.h"
19 
20 #if LV_USE_XML
21 
22 /**********************
23  *      TYPEDEFS
24  **********************/
25 
26 typedef struct _lv_xml_style_t {
27     const char * name;
28     const char * long_name;
29     lv_style_t style;
30 } lv_xml_style_t;
31 
32 /**********************
33  * GLOBAL PROTOTYPES
34  **********************/
35 
36 /**
37  * Add a style to `ctx` and set the style properties from `attrs`
38  * @param ctx       add styles here. (Constants should be already added as style properties might use them)
39  * @param attrs     list of attribute names and values
40  */
41 void lv_xml_style_register(lv_xml_component_ctx_t * ctx, const char ** attrs);
42 
43 /**
44  * Add the styles to an object. Handles multiple styles and selectors too.
45  * @param state     the parser state
46  * @param obj       the target widget
47  * @param text      the styles' string, e.g. "blue red:pressed:knob"
48  */
49 void lv_xml_style_add_to_obj(lv_xml_parser_state_t * state, lv_obj_t * obj, const char * text);
50 
51 /**
52  * Convert a style state to enum
53  * @param txt       e.g. "pressed"
54  * @return          the enum `LV_STATE_PRESSED`
55  */
56 lv_state_t lv_xml_style_state_to_enum(const char * txt);
57 
58 /**
59  * Convert a style part to enum
60  * @param txt       e.g. "knob"
61  * @return          the enum `LV_PART_KNOB`
62  */
63 lv_part_t lv_xml_style_part_to_enum(const char * txt);
64 
65 /**
66  * Decompose a string like `"style1:pressed:checked:knob"` to style name and selector
67  * @param txt           the input string
68  * @param selector      store the selectors here
69  * @return              the style name or `NULL` on any error
70  */
71 const char * lv_xml_style_string_process(char * txt, lv_style_selector_t * selector);
72 
73 /**
74  * Find a style by name which was added by `lv_xml_style_register`
75  * @param ctx       the default context to search in
76  * @param name      the name of the style. Can start with a component name prefix (e.g. `my_button.blue`) to overwrite the ctx
77  * @return          the style structure
78  */
79 lv_xml_style_t * lv_xml_get_style_by_name(lv_xml_component_ctx_t * ctx, const char * name);
80 
81 /**********************
82  *      MACROS
83  **********************/
84 
85 #endif /* LV_USE_XML */
86 
87 #ifdef __cplusplus
88 } /*extern "C"*/
89 #endif
90 
91 #endif /*LV_XML_STYLE_H*/
92