1 /**
2 * @file lv_style.h
3 *
4 */
5
6 #ifndef LV_STYLE_H
7 #define LV_STYLE_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #include <stdbool.h>
17 #include "../lv_font/lv_font.h"
18 #include "../lv_misc/lv_color.h"
19 #include "../lv_misc/lv_area.h"
20 #include "../lv_misc/lv_anim.h"
21 #include "../lv_misc/lv_types.h"
22 #include "../lv_misc/lv_debug.h"
23 #include "../lv_draw/lv_draw_blend.h"
24
25 /*********************
26 * DEFINES
27 *********************/
28
29 #define LV_RADIUS_CIRCLE (0x7FFF) /**< A very big radius to always draw as circle*/
30 LV_EXPORT_CONST_INT(LV_RADIUS_CIRCLE);
31
32 #define LV_DEBUG_STYLE_SENTINEL_VALUE 0x2288AAEE
33 #define LV_DEBUG_STYLE_LIST_SENTINEL_VALUE 0x9977CCBB
34
35 #define LV_STYLE_PROP_INIT(name, group, id, attr) name = (((group << 4) + id) | ((attr) << 8))
36
37 #define LV_STYLE_ID_MASK 0x00FF
38
39 #define LV_STYLE_ATTR_NONE 0
40 #define LV_STYLE_ATTR_INHERIT (1 << 7)
41
42 #define _LV_STYLE_CLOSEING_PROP 0xFF
43
44 #define LV_STYLE_TRANS_NUM_MAX 6
45
46 #define LV_STYLE_PROP_ALL 0xFF
47
48 /**********************
49 * TYPEDEFS
50 **********************/
51
52 /*Border types (Use 'OR'ed values)*/
53 enum {
54 LV_BORDER_SIDE_NONE = 0x00,
55 LV_BORDER_SIDE_BOTTOM = 0x01,
56 LV_BORDER_SIDE_TOP = 0x02,
57 LV_BORDER_SIDE_LEFT = 0x04,
58 LV_BORDER_SIDE_RIGHT = 0x08,
59 LV_BORDER_SIDE_FULL = 0x0F,
60 LV_BORDER_SIDE_INTERNAL = 0x10, /**< FOR matrix-like objects (e.g. Button matrix)*/
61 _LV_BORDER_SIDE_LAST
62 };
63 typedef uint8_t lv_border_side_t;
64
65 enum {
66 LV_GRAD_DIR_NONE,
67 LV_GRAD_DIR_VER,
68 LV_GRAD_DIR_HOR,
69 _LV_GRAD_DIR_LAST
70 };
71
72 typedef uint8_t lv_grad_dir_t;
73
74 /*Text decorations (Use 'OR'ed values)*/
75 enum {
76 LV_TEXT_DECOR_NONE = 0x00,
77 LV_TEXT_DECOR_UNDERLINE = 0x01,
78 LV_TEXT_DECOR_STRIKETHROUGH = 0x02,
79 _LV_TEXT_DECOR_LAST
80 };
81
82 typedef uint8_t lv_text_decor_t;
83
84 typedef uint8_t lv_style_attr_t;
85
86 #define LV_STYLE_ATTR_GET_INHERIT(f) ((f)&0x80)
87 #define LV_STYLE_ATTR_GET_STATE(f) ((f)&0x7F)
88
89 #define LV_STYLE_ID_VALUE 0x0 /*max 9 pcs*/
90 #define LV_STYLE_ID_COLOR 0x9 /*max 3 pcs*/
91 #define LV_STYLE_ID_OPA 0xC /*max 2 pcs*/
92 #define LV_STYLE_ID_PTR 0xE /*max 2 pcs*/
93
94 enum {
95 /*Skip 0th property*/
96 LV_STYLE_PROP_INIT(LV_STYLE_RADIUS, 0x0, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
97 LV_STYLE_PROP_INIT(LV_STYLE_CLIP_CORNER, 0x0, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
98 LV_STYLE_PROP_INIT(LV_STYLE_SIZE, 0x0, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
99 LV_STYLE_PROP_INIT(LV_STYLE_TRANSFORM_WIDTH, 0x0, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
100 LV_STYLE_PROP_INIT(LV_STYLE_TRANSFORM_HEIGHT, 0x0, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE),
101 LV_STYLE_PROP_INIT(LV_STYLE_TRANSFORM_ANGLE, 0x0, LV_STYLE_ID_VALUE + 6, LV_STYLE_ATTR_NONE),
102 LV_STYLE_PROP_INIT(LV_STYLE_TRANSFORM_ZOOM, 0x0, LV_STYLE_ID_VALUE + 7, LV_STYLE_ATTR_NONE),
103 LV_STYLE_PROP_INIT(LV_STYLE_OPA_SCALE, 0x0, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT),
104
105 LV_STYLE_PROP_INIT(LV_STYLE_PAD_TOP, 0x1, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
106 LV_STYLE_PROP_INIT(LV_STYLE_PAD_BOTTOM, 0x1, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
107 LV_STYLE_PROP_INIT(LV_STYLE_PAD_LEFT, 0x1, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
108 LV_STYLE_PROP_INIT(LV_STYLE_PAD_RIGHT, 0x1, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
109 LV_STYLE_PROP_INIT(LV_STYLE_PAD_INNER, 0x1, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
110 LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_TOP, 0x1, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE),
111 LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_BOTTOM, 0x1, LV_STYLE_ID_VALUE + 6, LV_STYLE_ATTR_NONE),
112 LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_LEFT, 0x1, LV_STYLE_ID_VALUE + 7, LV_STYLE_ATTR_NONE),
113 LV_STYLE_PROP_INIT(LV_STYLE_MARGIN_RIGHT, 0x1, LV_STYLE_ID_VALUE + 8, LV_STYLE_ATTR_NONE),
114
115 LV_STYLE_PROP_INIT(LV_STYLE_BG_BLEND_MODE, 0x2, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
116 LV_STYLE_PROP_INIT(LV_STYLE_BG_MAIN_STOP, 0x2, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
117 LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_STOP, 0x2, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
118 LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_DIR, 0x2, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
119 LV_STYLE_PROP_INIT(LV_STYLE_BG_COLOR, 0x2, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
120 LV_STYLE_PROP_INIT(LV_STYLE_BG_GRAD_COLOR, 0x2, LV_STYLE_ID_COLOR + 1, LV_STYLE_ATTR_NONE),
121 LV_STYLE_PROP_INIT(LV_STYLE_BG_OPA, 0x2, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
122
123 LV_STYLE_PROP_INIT(LV_STYLE_BORDER_WIDTH, 0x3, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
124 LV_STYLE_PROP_INIT(LV_STYLE_BORDER_SIDE, 0x3, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
125 LV_STYLE_PROP_INIT(LV_STYLE_BORDER_BLEND_MODE, 0x3, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
126 LV_STYLE_PROP_INIT(LV_STYLE_BORDER_POST, 0x3, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
127 LV_STYLE_PROP_INIT(LV_STYLE_BORDER_COLOR, 0x3, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
128 LV_STYLE_PROP_INIT(LV_STYLE_BORDER_OPA, 0x3, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
129
130 LV_STYLE_PROP_INIT(LV_STYLE_OUTLINE_WIDTH, 0x4, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
131 LV_STYLE_PROP_INIT(LV_STYLE_OUTLINE_PAD, 0x4, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
132 LV_STYLE_PROP_INIT(LV_STYLE_OUTLINE_BLEND_MODE, 0x4, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
133 LV_STYLE_PROP_INIT(LV_STYLE_OUTLINE_COLOR, 0x4, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
134 LV_STYLE_PROP_INIT(LV_STYLE_OUTLINE_OPA, 0x4, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
135
136 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_WIDTH, 0x5, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
137 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_OFS_X, 0x5, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
138 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_OFS_Y, 0x5, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
139 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_SPREAD, 0x5, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
140 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_BLEND_MODE, 0x5, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
141 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_COLOR, 0x5, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
142 LV_STYLE_PROP_INIT(LV_STYLE_SHADOW_OPA, 0x5, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
143
144 LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_BLEND_MODE, 0x6, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
145 LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_REPEAT, 0x6, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
146 LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_RECOLOR, 0x6, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
147 LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_OPA, 0x6, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
148 LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_RECOLOR_OPA, 0x6, LV_STYLE_ID_OPA + 1, LV_STYLE_ATTR_NONE),
149 LV_STYLE_PROP_INIT(LV_STYLE_PATTERN_IMAGE, 0x6, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_NONE),
150
151 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_LETTER_SPACE, 0x7, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
152 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_LINE_SPACE, 0x7, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
153 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_BLEND_MODE, 0x7, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
154 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_OFS_X, 0x7, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
155 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_OFS_Y, 0x7, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
156 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_ALIGN, 0x7, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE),
157 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_COLOR, 0x7, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
158 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_OPA, 0x7, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
159 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_FONT, 0x7, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_NONE),
160 LV_STYLE_PROP_INIT(LV_STYLE_VALUE_STR, 0x7, LV_STYLE_ID_PTR + 1, LV_STYLE_ATTR_NONE),
161
162 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_LETTER_SPACE, 0x8, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_INHERIT),
163 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_LINE_SPACE, 0x8, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_INHERIT),
164 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_DECOR, 0x8, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_INHERIT),
165 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_BLEND_MODE, 0x8, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_INHERIT),
166 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_COLOR, 0x8, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_INHERIT),
167 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_SEL_COLOR, 0x8, LV_STYLE_ID_COLOR + 1, LV_STYLE_ATTR_INHERIT),
168 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_OPA, 0x8, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT),
169 LV_STYLE_PROP_INIT(LV_STYLE_TEXT_FONT, 0x8, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_INHERIT),
170
171 LV_STYLE_PROP_INIT(LV_STYLE_LINE_WIDTH, 0x9, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
172 LV_STYLE_PROP_INIT(LV_STYLE_LINE_BLEND_MODE, 0x9, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
173 LV_STYLE_PROP_INIT(LV_STYLE_LINE_DASH_WIDTH, 0x9, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
174 LV_STYLE_PROP_INIT(LV_STYLE_LINE_DASH_GAP, 0x9, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
175 LV_STYLE_PROP_INIT(LV_STYLE_LINE_ROUNDED, 0x9, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
176 LV_STYLE_PROP_INIT(LV_STYLE_LINE_COLOR, 0x9, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
177 LV_STYLE_PROP_INIT(LV_STYLE_LINE_OPA, 0x9, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_NONE),
178
179 LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_BLEND_MODE, 0xA, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_INHERIT),
180 LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_RECOLOR, 0xA, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_INHERIT),
181 LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_OPA, 0xA, LV_STYLE_ID_OPA + 0, LV_STYLE_ATTR_INHERIT),
182 LV_STYLE_PROP_INIT(LV_STYLE_IMAGE_RECOLOR_OPA, 0xA, LV_STYLE_ID_OPA + 1, LV_STYLE_ATTR_INHERIT),
183
184 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_TIME, 0xB, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
185 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_DELAY, 0xB, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
186 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PROP_1, 0xB, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
187 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PROP_2, 0xB, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
188 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PROP_3, 0xB, LV_STYLE_ID_VALUE + 4, LV_STYLE_ATTR_NONE),
189 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PROP_4, 0xB, LV_STYLE_ID_VALUE + 5, LV_STYLE_ATTR_NONE),
190 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PROP_5, 0xB, LV_STYLE_ID_VALUE + 6, LV_STYLE_ATTR_NONE),
191 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PROP_6, 0xB, LV_STYLE_ID_VALUE + 7, LV_STYLE_ATTR_NONE),
192 LV_STYLE_PROP_INIT(LV_STYLE_TRANSITION_PATH, 0xB, LV_STYLE_ID_PTR + 0, LV_STYLE_ATTR_NONE),
193
194 LV_STYLE_PROP_INIT(LV_STYLE_SCALE_WIDTH, 0xC, LV_STYLE_ID_VALUE + 0, LV_STYLE_ATTR_NONE),
195 LV_STYLE_PROP_INIT(LV_STYLE_SCALE_BORDER_WIDTH, 0xC, LV_STYLE_ID_VALUE + 1, LV_STYLE_ATTR_NONE),
196 LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_BORDER_WIDTH, 0xC, LV_STYLE_ID_VALUE + 2, LV_STYLE_ATTR_NONE),
197 LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_LINE_WIDTH, 0xC, LV_STYLE_ID_VALUE + 3, LV_STYLE_ATTR_NONE),
198 LV_STYLE_PROP_INIT(LV_STYLE_SCALE_GRAD_COLOR, 0xC, LV_STYLE_ID_COLOR + 0, LV_STYLE_ATTR_NONE),
199 LV_STYLE_PROP_INIT(LV_STYLE_SCALE_END_COLOR, 0xC, LV_STYLE_ID_COLOR + 1, LV_STYLE_ATTR_NONE),
200 };
201
202 typedef uint16_t lv_style_property_t;
203
204 #define LV_STYLE_STATE_POS 8
205 #define LV_STYLE_STATE_MASK 0x7F00
206 #define LV_STYLE_INHERIT_MASK 0x8000
207
208 typedef uint16_t lv_style_state_t;
209
210 typedef struct {
211 uint8_t * map;
212 #if LV_USE_ASSERT_STYLE
213 uint32_t sentinel;
214 #endif
215 } lv_style_t;
216
217 typedef int16_t lv_style_int_t;
218
219 typedef struct {
220 lv_style_t ** style_list;
221 #if LV_USE_ASSERT_STYLE
222 uint32_t sentinel;
223 #endif
224 uint32_t style_cnt : 6;
225 uint32_t has_local : 1;
226 uint32_t has_trans : 1;
227 uint32_t skip_trans : 1; /*1: Temporally skip the transition style if any*/
228 uint32_t ignore_trans : 1; /*1: Mark that this style list shouldn't receive transitions at all*/
229 uint32_t valid_cache : 1; /*1: The cache is valid and can be used*/
230 uint32_t ignore_cache : 1; /*1: Ignore cache while getting value of properties*/
231
232 uint32_t radius_zero : 1;
233 uint32_t opa_scale_cover : 1;
234 uint32_t clip_corner_off : 1;
235 uint32_t transform_all_zero : 1;
236 uint32_t pad_all_zero : 1;
237 uint32_t margin_all_zero : 1;
238 uint32_t blend_mode_all_normal : 1;
239 uint32_t bg_opa_transp : 1;
240 uint32_t bg_opa_cover : 1;
241
242 uint32_t border_width_zero : 1;
243 uint32_t border_side_full : 1;
244 uint32_t border_post_off : 1;
245
246 uint32_t outline_width_zero : 1;
247 uint32_t pattern_img_null : 1;
248 uint32_t shadow_width_zero : 1;
249 uint32_t value_txt_str : 1;
250 uint32_t img_recolor_opa_transp : 1;
251
252 uint32_t text_space_zero : 1;
253 uint32_t text_decor_none : 1;
254 uint32_t text_font_normal : 1;
255 } lv_style_list_t;
256
257 /**********************
258 * GLOBAL PROTOTYPES
259 **********************/
260
261 /**
262 * Initialize a style
263 * @param style pointer to a style to initialize
264 */
265 void lv_style_init(lv_style_t * style);
266
267 /**
268 * Copy a style with all its properties
269 * @param style_dest pointer to the destination style. (Should be initialized with `lv_style_init()`)
270 * @param style_src pointer to the source (to copy )style
271 */
272 void lv_style_copy(lv_style_t * style_dest, const lv_style_t * style_src);
273
274 /**
275 * Initialize a style list
276 * @param list a style list to initialize
277 */
278 void lv_style_list_init(lv_style_list_t * list);
279
280 /**
281 * Copy a style list with all its styles and local style properties
282 * @param list_dest pointer to the destination style list. (should be initialized with `lv_style_list_init()`)
283 * @param list_src pointer to the source (to copy) style list.
284 */
285 void lv_style_list_copy(lv_style_list_t * list_dest, const lv_style_list_t * list_src);
286
287 /**
288 * Add a style to a style list.
289 * Only the the style pointer will be saved so the shouldn't be a local variable.
290 * (It should be static, global or dynamically allocated)
291 * @param list pointer to a style list
292 * @param style pointer to a style to add
293 */
294 void _lv_style_list_add_style(lv_style_list_t * list, lv_style_t * style);
295
296 /**
297 * Remove a style from a style list
298 * @param style_list pointer to a style list
299 * @param style pointer to a style to remove
300 */
301 void _lv_style_list_remove_style(lv_style_list_t * list, lv_style_t * style);
302
303 /**
304 * Remove all styles added from style list, clear the local style, transition style and free all allocated memories.
305 * Leave `ignore_trans` flag as it is.
306 * @param list pointer to a style list.
307 */
308 void _lv_style_list_reset(lv_style_list_t * style_list);
309
lv_style_list_get_style(lv_style_list_t * list,uint8_t id)310 static inline lv_style_t * lv_style_list_get_style(lv_style_list_t * list, uint8_t id)
311 {
312 if(list->has_trans && list->skip_trans) id++;
313 if(list->style_cnt == 0 || id >= list->style_cnt) return NULL;
314 return list->style_list[id];
315 }
316
317 /**
318 * Clear all properties from a style and all allocated memories.
319 * @param style pointer to a style
320 */
321 void lv_style_reset(lv_style_t * style);
322
323 /**
324 * Get the size of the properties in a style in bytes
325 * @param style pointer to a style
326 * @return size of the properties in bytes
327 */
328 uint16_t _lv_style_get_mem_size(const lv_style_t * style);
329
330 /**
331 * Copy a style to an other
332 * @param dest pointer to the destination style
333 * @param src pointer to the source style
334 */
335 void lv_style_copy(lv_style_t * dest, const lv_style_t * src);
336
337 /**
338 * Remove a property from a style
339 * @param style pointer to a style
340 * @param prop a style property ORed with a state.
341 * E.g. `LV_STYLE_BORDER_WIDTH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
342 * @return true: the property was found and removed; false: the property wasn't found
343 */
344 bool lv_style_remove_prop(lv_style_t * style, lv_style_property_t prop);
345
346 /**
347 * Set an integer typed property in a style.
348 * @param style pointer to a style where the property should be set
349 * @param prop a style property ORed with a state.
350 * E.g. `LV_STYLE_BORDER_WIDTH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
351 * @param value the value to set
352 * @note shouldn't be used directly. Use the specific property set functions instead.
353 * For example: `lv_style_set_border_width()`
354 * @note for performance reasons it's not checked if the property really has integer type
355 */
356 void _lv_style_set_int(lv_style_t * style, lv_style_property_t prop, lv_style_int_t value);
357
358 /**
359 * Set a color typed property in a style.
360 * @param style pointer to a style where the property should be set
361 * @param prop a style property ORed with a state.
362 * E.g. `LV_STYLE_BORDER_COLOR | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
363 * @param value the value to set
364 * @note shouldn't be used directly. Use the specific property set functions instead.
365 * For example: `lv_style_set_border_color()`
366 * @note for performance reasons it's not checked if the property really has color type
367 */
368 void _lv_style_set_color(lv_style_t * style, lv_style_property_t prop, lv_color_t color);
369
370 /**
371 * Set an opacity typed property in a style.
372 * @param style pointer to a style where the property should be set
373 * @param prop a style property ORed with a state.
374 * E.g. `LV_STYLE_BORDER_OPA | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
375 * @param value the value to set
376 * @note shouldn't be used directly. Use the specific property set functions instead.
377 * For example: `lv_style_set_border_opa()`
378 * @note for performance reasons it's not checked if the property really has opacity type
379 */
380 void _lv_style_set_opa(lv_style_t * style, lv_style_property_t prop, lv_opa_t opa);
381
382 /**
383 * Set a pointer typed property in a style.
384 * @param style pointer to a style where the property should be set
385 * @param prop a style property ORed with a state.
386 * E.g. `LV_STYLE_TEXT_POINTER | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
387 * @param value the value to set
388 * @note shouldn't be used directly. Use the specific property set functions instead.
389 * For example: `lv_style_set_border_width()`
390 * @note for performance reasons it's not checked if the property really has pointer type
391 */
392 void _lv_style_set_ptr(lv_style_t * style, lv_style_property_t prop, const void * p);
393
394 /**
395 * Get an integer typed property from a style.
396 * @param style pointer to a style from where the property should be get
397 * @param prop a style property ORed with a state.
398 * E.g. `LV_STYLE_BORDER_WIDTH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
399 * @param res pointer to a buffer to store the result value
400 * @return -1: the property wasn't found in the style.
401 * The matching state bits of the desired state (in `prop`) and the best matching property's state
402 * Higher value means match in higher precedence state.
403 * @note shouldn't be used directly. Use the specific property get functions instead.
404 * For example: `lv_style_get_border_width()`
405 * @note for performance reasons it's not checked if the property really has integer type
406 */
407 int16_t _lv_style_get_int(const lv_style_t * style, lv_style_property_t prop, void * res);
408
409 /**
410 * Get a color typed property from a style.
411 * @param style pointer to a style from where the property should be get
412 * @param prop a style property ORed with a state.
413 * E.g. `LV_STYLE_BORDER_COLOR | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
414 * @param res pointer to a buffer to store the result value
415 * @return -1: the property wasn't found in the style.
416 * The matching state bits of the desired state (in `prop`) and the best matching property's state
417 * Higher value means match in higher precedence state.
418 * @note shouldn't be used directly. Use the specific property get functions instead.
419 * For example: `lv_style_get_border_color()`
420 * @note for performance reasons it's not checked if the property really has color type
421 */
422 int16_t _lv_style_get_color(const lv_style_t * style, lv_style_property_t prop, void * res);
423
424 /**
425 * Get an opacity typed property from a style.
426 * @param style pointer to a style from where the property should be get
427 * @param prop a style property ORed with a state.
428 * E.g. `LV_STYLE_BORDER_OPA | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
429 * @param res pointer to a buffer to store the result value
430 * @return -1: the property wasn't found in the style.
431 * The matching state bits of the desired state (in `prop`) and the best matching property's state
432 * Higher value means match in higher precedence state.
433 * @note shouldn't be used directly. Use the specific property get functions instead.
434 * For example: `lv_style_get_border_opa()`
435 * @note for performance reasons it's not checked if the property really has opacity type
436 */
437 int16_t _lv_style_get_opa(const lv_style_t * style, lv_style_property_t prop, void * res);
438
439 /**
440 * Get a pointer typed property from a style.
441 * @param style pointer to a style from where the property should be get
442 * @param prop a style property ORed with a state.
443 * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
444 * @param res pointer to a buffer to store the result value
445 * @return -1: the property wasn't found in the style.
446 * The matching state bits of the desired state (in `prop`) and the best matching property's state
447 * Higher value means match in higher precedence state.
448 * @note shouldn't be used directly. Use the specific property get functions instead.
449 * For example: `lv_style_get_text_font()`
450 * @note for performance reasons it's not checked if the property really has pointer type
451 */
452 int16_t _lv_style_get_ptr(const lv_style_t * style, lv_style_property_t prop, void * res);
453
454 /**
455 * Get the local style of a style list
456 * @param list pointer to a style list where the local property should be set
457 * @return pointer to the local style if exists else `NULL`.
458 */
459 lv_style_t * lv_style_list_get_local_style(lv_style_list_t * list);
460
461 /**
462 * Get the transition style of a style list
463 * @param list pointer to a style list where the local property should be set
464 * @return pointer to the transition style if exists else `NULL`.
465 */
466 lv_style_t * _lv_style_list_get_transition_style(lv_style_list_t * list);
467
468 /**
469 * Allocate the transition style in a style list. If already exists simply return it.
470 * @param list pointer to a style list
471 * @return the transition style of a style list
472 */
473 lv_style_t * _lv_style_list_add_trans_style(lv_style_list_t * list);
474
475 /**
476 * Set a local integer typed property in a style list.
477 * @param list pointer to a style list where the local property should be set
478 * @param prop a style property ORed with a state.
479 * E.g. `LV_STYLE_BORDER_WIDTH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
480 * @param value the value to set
481 * @note for performance reasons it's not checked if the property really has integer type
482 */
483 void _lv_style_list_set_local_int(lv_style_list_t * list, lv_style_property_t prop, lv_style_int_t value);
484
485 /**
486 * Set a local color typed property in a style list.
487 * @param list pointer to a style list where the local property should be set
488 * @param prop a style property ORed with a state.
489 * E.g. `LV_STYLE_BORDER_COLOR | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
490 * @param value the value to set
491 * @note for performance reasons it's not checked if the property really has color type
492 */
493 void _lv_style_list_set_local_color(lv_style_list_t * list, lv_style_property_t prop, lv_color_t value);
494
495 /**
496 * Set a local opacity typed property in a style list.
497 * @param list pointer to a style list where the local property should be set
498 * @param prop a style property ORed with a state.
499 * E.g. `LV_STYLE_BORDER_OPA | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
500 * @param value the value to set
501 * @note for performance reasons it's not checked if the property really has opacity type
502 */
503 void _lv_style_list_set_local_opa(lv_style_list_t * list, lv_style_property_t prop, lv_opa_t value);
504
505 /**
506 * Set a local pointer typed property in a style list.
507 * @param list pointer to a style list where the local property should be set
508 * @param prop a style property ORed with a state.
509 * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
510 * @param value the value to set
511 * @note for performance reasons it's not checked if the property really has pointer type
512 */
513 void _lv_style_list_set_local_ptr(lv_style_list_t * list, lv_style_property_t prop, const void * value);
514
515 /**
516 * Get an integer typed property from a style list.
517 * It will return the property which match best with given state.
518 * @param list pointer to a style list from where the property should be get
519 * @param prop a style property ORed with a state.
520 * E.g. `LV_STYLE_BORDER_WIDTH | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
521 * @param res pointer to a buffer to store the result
522 * @return LV_RES_OK: there was a matching property in the list
523 * LV_RES_INV: there was NO matching property in the list
524 * @note for performance reasons it's not checked if the property really has integer type
525 */
526 lv_res_t _lv_style_list_get_int(lv_style_list_t * list, lv_style_property_t prop, lv_style_int_t * res);
527
528 /**
529 * Get a color typed property from a style list.
530 * It will return the property which match best with given state.
531 * @param list pointer to a style list from where the property should be get
532 * @param prop a style property ORed with a state.
533 * E.g. `LV_STYLE_BORDER_COLOR | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
534 * @param res pointer to a buffer to store the result
535 * @return LV_RES_OK: there was a matching property in the list
536 * LV_RES_INV: there was NO matching property in the list
537 * @note for performance reasons it's not checked if the property really has color type
538 */
539 lv_res_t _lv_style_list_get_color(lv_style_list_t * list, lv_style_property_t prop, lv_color_t * res);
540
541
542 /**
543 * Get an opacity typed property from a style list.
544 * It will return the property which match best with given state.
545 * @param list pointer to a style list from where the property should be get
546 * @param prop a style property ORed with a state.
547 * E.g. `LV_STYLE_BORDER_OPA | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
548 * @param res pointer to a buffer to store the result
549 * @return LV_RES_OK: there was a matching property in the list
550 * LV_RES_INV: there was NO matching property in the list
551 * @note for performance reasons it's not checked if the property really has opacity type
552 */
553 lv_res_t _lv_style_list_get_opa(lv_style_list_t * list, lv_style_property_t prop, lv_opa_t * res);
554
555 /**
556 * Get a pointer typed property from a style list.
557 * It will return the property which match best with given state.
558 * @param list pointer to a style list from where the property should be get
559 * @param prop a style property ORed with a state.
560 * E.g. `LV_STYLE_TEXT_FONT | (LV_STATE_PRESSED << LV_STYLE_STATE_POS)`
561 * @param res pointer to a buffer to store the result
562 * @return LV_RES_OK: there was a matching property in the list
563 * LV_RES_INV: there was NO matching property in the list
564 * @note for performance reasons it's not checked if the property really has pointer type
565 */
566 lv_res_t _lv_style_list_get_ptr(lv_style_list_t * list, lv_style_property_t prop, const void ** res);
567
568 /**
569 * Check whether a style is valid (initialized correctly)
570 * @param style pointer to a style
571 * @return true: valid
572 */
573 bool lv_debug_check_style(const lv_style_t * style);
574
575 /**
576 * Check whether a style list is valid (initialized correctly)
577 * @param style pointer to a style
578 * @return true: valid
579 */
580 bool lv_debug_check_style_list(const lv_style_list_t * list);
581
582 /*************************
583 * GLOBAL VARIABLES
584 *************************/
585
586 /**********************
587 * MACROS
588 **********************/
589
590 /**
591 * Create and initialize a `static` style
592 * Example:
593 * LV_STYLE_CREATE(my_style, &style_to_copy);
594 * is equivalent to
595 * static lv_style_t my_style;
596 * lv_style_init(&my_style);
597 * lv_style_copy(&my_style, &style_to_copy);
598 */
599 #define LV_STYLE_CREATE(name, copy_p) static lv_style_t name; lv_style_init(&name); lv_style_copy(&name, copy_p);
600
601
602
603 #if LV_USE_DEBUG
604
605 # ifndef LV_DEBUG_IS_STYLE
606 # define LV_DEBUG_IS_STYLE(style_p) (lv_debug_check_style(style_p))
607 # endif
608
609 # ifndef LV_DEBUG_IS_STYLE_LIST
610 # define LV_DEBUG_IS_STYLE_LIST(list_p) (lv_debug_check_style_list(list_p))
611 # endif
612
613 # if LV_USE_ASSERT_STYLE
614 # ifndef LV_ASSERT_STYLE
615 # define LV_ASSERT_STYLE(style_p) LV_DEBUG_ASSERT(LV_DEBUG_IS_STYLE(style_p), "Invalid style", style_p);
616 # endif
617 # ifndef LV_ASSERT_STYLE_LIST
618 # define LV_ASSERT_STYLE_LIST(list_p) LV_DEBUG_ASSERT(LV_DEBUG_IS_STYLE_LIST(list_p), "Invalid style list", list_p);
619 # endif
620 # else
621 # define LV_ASSERT_STYLE(style_p)
622 # define LV_ASSERT_STYLE_LIST(list_p)
623 # endif
624
625 #else
626 # define LV_ASSERT_STYLE(p)
627 # define LV_ASSERT_STYLE_LIST(p)
628 #endif
629
630 #ifdef __cplusplus
631 } /* extern "C" */
632 #endif
633
634 #endif /*LV_STYLE_H*/
635