mikroSDK Reference Manual
lv_style.h
Go to the documentation of this file.
1
6#ifndef LV_STYLE_H
7#define LV_STYLE_H
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
13/*********************
14 * INCLUDES
15 *********************/
16#include <stdbool.h>
17#include <stdint.h>
18#include "../font/lv_font.h"
19#include "lv_color.h"
20#include "lv_area.h"
21#include "lv_anim.h"
22#include "lv_txt.h"
23#include "lv_types.h"
24#include "lv_assert.h"
25#include "lv_bidi.h"
26
27/*********************
28 * DEFINES
29 *********************/
30
31#define LV_STYLE_SENTINEL_VALUE 0xAABBCCDD
32
38#define LV_STYLE_PROP_FLAG_NONE (0)
39#define LV_STYLE_PROP_INHERIT (1 << 0) /*Inherited*/
40#define LV_STYLE_PROP_EXT_DRAW (1 << 1) /*Requires ext. draw size update when changed*/
41#define LV_STYLE_PROP_LAYOUT_REFR (1 << 2) /*Requires layout update when changed*/
42#define LV_STYLE_PROP_PARENT_LAYOUT_REFR (1 << 3) /*Requires layout update on parent when changed*/
43#define LV_STYLE_PROP_LAYER_REFR (1 << 4) /*Affects layer handling*/
44#define LV_STYLE_PROP_ALL (0x1F) /*Indicating all flags*/
45
49#define LV_IMG_ZOOM_NONE 256 /*Value for not zooming the image*/
50LV_EXPORT_CONST_INT(LV_IMG_ZOOM_NONE);
51
52// *INDENT-OFF*
53#if LV_USE_ASSERT_STYLE
54#define LV_STYLE_CONST_INIT(var_name, prop_array) \
55 const lv_style_t var_name = { \
56 .sentinel = LV_STYLE_SENTINEL_VALUE, \
57 .v_p = { .const_props = prop_array }, \
58 .has_group = 0xFF, \
59 .prop1 = LV_STYLE_PROP_ANY, \
60 .prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \
61 }
62#else
63#define LV_STYLE_CONST_INIT(var_name, prop_array) \
64 const lv_style_t var_name = { \
65 .v_p = { .const_props = prop_array }, \
66 .has_group = 0xFF, \
67 .prop1 = LV_STYLE_PROP_ANY, \
68 .prop_cnt = (sizeof(prop_array) / sizeof((prop_array)[0])), \
69 }
70#endif
71// *INDENT-ON*
72
73#define LV_STYLE_PROP_META_INHERIT 0x8000
74#define LV_STYLE_PROP_META_INITIAL 0x4000
75#define LV_STYLE_PROP_META_MASK (LV_STYLE_PROP_META_INHERIT | LV_STYLE_PROP_META_INITIAL)
76
77#define LV_STYLE_PROP_ID_MASK(prop) ((lv_style_prop_t)((prop) & ~LV_STYLE_PROP_META_MASK))
78
79/**********************
80 * TYPEDEFS
81 **********************/
82
86enum {
92};
93
94typedef uint8_t lv_blend_mode_t;
95
100enum {
101 LV_TEXT_DECOR_NONE = 0x00,
102 LV_TEXT_DECOR_UNDERLINE = 0x01,
103 LV_TEXT_DECOR_STRIKETHROUGH = 0x02,
104};
105
106typedef uint8_t lv_text_decor_t;
107
112enum {
113 LV_BORDER_SIDE_NONE = 0x00,
114 LV_BORDER_SIDE_BOTTOM = 0x01,
115 LV_BORDER_SIDE_TOP = 0x02,
116 LV_BORDER_SIDE_LEFT = 0x04,
117 LV_BORDER_SIDE_RIGHT = 0x08,
118 LV_BORDER_SIDE_FULL = 0x0F,
120};
121typedef uint8_t lv_border_side_t;
122
126enum {
130};
131
132typedef uint8_t lv_grad_dir_t;
133
138enum {
142};
143
144typedef uint8_t lv_dither_mode_t;
145
149typedef struct {
150 lv_color_t color;
151 uint8_t frac;
153
155typedef struct {
156 lv_gradient_stop_t stops[LV_GRADIENT_MAX_STOPS];
157 uint8_t stops_count;
158 lv_grad_dir_t dir : 3;
160 lv_dither_mode_t dither : 3;
163
167typedef union {
168 int32_t num;
169 const void * ptr;
170 lv_color_t color;
172
178typedef enum {
179 LV_STYLE_PROP_INV = 0,
180
181 /*Group 0*/
182 LV_STYLE_WIDTH = 1,
183 LV_STYLE_MIN_WIDTH = 2,
184 LV_STYLE_MAX_WIDTH = 3,
185 LV_STYLE_HEIGHT = 4,
186 LV_STYLE_MIN_HEIGHT = 5,
187 LV_STYLE_MAX_HEIGHT = 6,
188 LV_STYLE_X = 7,
189 LV_STYLE_Y = 8,
190 LV_STYLE_ALIGN = 9,
191 LV_STYLE_LAYOUT = 10,
192 LV_STYLE_RADIUS = 11,
193
194 /*Group 1*/
195 LV_STYLE_PAD_TOP = 16,
196 LV_STYLE_PAD_BOTTOM = 17,
197 LV_STYLE_PAD_LEFT = 18,
198 LV_STYLE_PAD_RIGHT = 19,
199 LV_STYLE_PAD_ROW = 20,
200 LV_STYLE_PAD_COLUMN = 21,
201 LV_STYLE_BASE_DIR = 22,
202 LV_STYLE_CLIP_CORNER = 23,
203
204 /*Group 2*/
205 LV_STYLE_BG_COLOR = 32,
206 LV_STYLE_BG_OPA = 33,
207 LV_STYLE_BG_GRAD_COLOR = 34,
208 LV_STYLE_BG_GRAD_DIR = 35,
209 LV_STYLE_BG_MAIN_STOP = 36,
210 LV_STYLE_BG_GRAD_STOP = 37,
211 LV_STYLE_BG_GRAD = 38,
212 LV_STYLE_BG_DITHER_MODE = 39,
213 LV_STYLE_BG_IMG_SRC = 40,
214 LV_STYLE_BG_IMG_OPA = 41,
215 LV_STYLE_BG_IMG_RECOLOR = 42,
216 LV_STYLE_BG_IMG_RECOLOR_OPA = 43,
217 LV_STYLE_BG_IMG_TILED = 44,
218
219 /*Group 3*/
220 LV_STYLE_BORDER_COLOR = 48,
221 LV_STYLE_BORDER_OPA = 49,
222 LV_STYLE_BORDER_WIDTH = 50,
223 LV_STYLE_BORDER_SIDE = 51,
224 LV_STYLE_BORDER_POST = 52,
225 LV_STYLE_OUTLINE_WIDTH = 53,
226 LV_STYLE_OUTLINE_COLOR = 54,
227 LV_STYLE_OUTLINE_OPA = 55,
228 LV_STYLE_OUTLINE_PAD = 56,
229
230 /*Group 4*/
231 LV_STYLE_SHADOW_WIDTH = 64,
232 LV_STYLE_SHADOW_OFS_X = 65,
233 LV_STYLE_SHADOW_OFS_Y = 66,
234 LV_STYLE_SHADOW_SPREAD = 67,
235 LV_STYLE_SHADOW_COLOR = 68,
236 LV_STYLE_SHADOW_OPA = 69,
237 LV_STYLE_IMG_OPA = 70,
238 LV_STYLE_IMG_RECOLOR = 71,
239 LV_STYLE_IMG_RECOLOR_OPA = 72,
240 LV_STYLE_LINE_WIDTH = 73,
241 LV_STYLE_LINE_DASH_WIDTH = 74,
242 LV_STYLE_LINE_DASH_GAP = 75,
243 LV_STYLE_LINE_ROUNDED = 76,
244 LV_STYLE_LINE_COLOR = 77,
245 LV_STYLE_LINE_OPA = 78,
246
247 /*Group 5*/
248 LV_STYLE_ARC_WIDTH = 80,
249 LV_STYLE_ARC_ROUNDED = 81,
250 LV_STYLE_ARC_COLOR = 82,
251 LV_STYLE_ARC_OPA = 83,
252 LV_STYLE_ARC_IMG_SRC = 84,
253 LV_STYLE_TEXT_COLOR = 85,
254 LV_STYLE_TEXT_OPA = 86,
255 LV_STYLE_TEXT_FONT = 87,
256 LV_STYLE_TEXT_LETTER_SPACE = 88,
257 LV_STYLE_TEXT_LINE_SPACE = 89,
258 LV_STYLE_TEXT_DECOR = 90,
259 LV_STYLE_TEXT_ALIGN = 91,
260
261 /*Group 6*/
262 LV_STYLE_OPA = 96,
263 LV_STYLE_COLOR_FILTER_DSC = 97,
264 LV_STYLE_COLOR_FILTER_OPA = 98,
265 LV_STYLE_ANIM = 99,
266 LV_STYLE_ANIM_TIME = 100,
267 LV_STYLE_ANIM_SPEED = 101,
268 LV_STYLE_TRANSITION = 102,
269 LV_STYLE_BLEND_MODE = 103,
270 LV_STYLE_TRANSFORM_WIDTH = 104,
271 LV_STYLE_TRANSFORM_HEIGHT = 105,
272 LV_STYLE_TRANSLATE_X = 106,
273 LV_STYLE_TRANSLATE_Y = 107,
274 LV_STYLE_TRANSFORM_ZOOM = 108,
275 LV_STYLE_TRANSFORM_ANGLE = 109,
276 LV_STYLE_TRANSFORM_PIVOT_X = 110,
277 LV_STYLE_TRANSFORM_PIVOT_Y = 111,
278
279 _LV_STYLE_LAST_BUILT_IN_PROP = 111,
280 _LV_STYLE_NUM_BUILT_IN_PROPS = _LV_STYLE_LAST_BUILT_IN_PROP + 1,
281
282 LV_STYLE_PROP_ANY = 0xFFFF,
283 _LV_STYLE_PROP_CONST = 0xFFFF /* magic value for const styles */
285
286enum {
287 LV_STYLE_RES_NOT_FOUND,
288 LV_STYLE_RES_FOUND,
289 LV_STYLE_RES_INHERIT
290};
291
292typedef uint8_t lv_style_res_t;
293
297typedef struct {
299#if LV_USE_USER_DATA
300 void * user_data;
301#endif
303 uint32_t time;
304 uint32_t delay;
306
310typedef struct {
311 lv_style_prop_t prop;
312 lv_style_value_t value;
314
318typedef struct {
319
320#if LV_USE_ASSERT_STYLE
321 uint32_t sentinel;
322#endif
323
324 /*If there is only one property store it directly.
325 *For more properties allocate an array*/
326 union {
327 lv_style_value_t value1;
328 uint8_t * values_and_props;
329 const lv_style_const_prop_t * const_props;
330 } v_p;
331
332 uint16_t prop1;
333 uint8_t has_group;
334 uint8_t prop_cnt;
335} lv_style_t;
336
337/**********************
338 * GLOBAL PROTOTYPES
339 **********************/
340
341
350
356
370lv_style_prop_t lv_style_register_prop(uint8_t flag);
371
376
384
394
402void lv_style_set_prop_meta(lv_style_t * style, lv_style_prop_t prop, uint16_t meta);
403
413lv_style_res_t lv_style_get_prop(const lv_style_t * style, lv_style_prop_t prop, lv_style_value_t * value);
414
428void lv_style_transition_dsc_init(lv_style_transition_dsc_t * tr, const lv_style_prop_t props[],
429 lv_anim_path_cb_t path_cb, uint32_t time, uint32_t delay, void * user_data);
430
437
448static inline lv_style_res_t lv_style_get_prop_inlined(const lv_style_t * style, lv_style_prop_t prop,
449 lv_style_value_t * value)
450{
451 if(style->prop1 == LV_STYLE_PROP_ANY) {
452 const lv_style_const_prop_t * const_prop;
453 uint32_t i;
454 for(i = 0; i < style->prop_cnt; i++) {
455 const_prop = style->v_p.const_props + i;
456 lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(const_prop->prop);
457 if(prop_id == prop) {
458 if(const_prop->prop & LV_STYLE_PROP_META_INHERIT)
459 return LV_STYLE_RES_INHERIT;
460 *value = (const_prop->prop & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(prop_id) : const_prop->value;
461 return LV_STYLE_RES_FOUND;
462 }
463 }
464 return LV_STYLE_RES_NOT_FOUND;
465 }
466
467 if(style->prop_cnt == 0) return LV_STYLE_RES_NOT_FOUND;
468
469 if(style->prop_cnt > 1) {
470 uint8_t * tmp = style->v_p.values_and_props + style->prop_cnt * sizeof(lv_style_value_t);
471 uint16_t * props = (uint16_t *)tmp;
472 uint32_t i;
473 for(i = 0; i < style->prop_cnt; i++) {
474 lv_style_prop_t prop_id = LV_STYLE_PROP_ID_MASK(props[i]);
475 if(prop_id == prop) {
476 if(props[i] & LV_STYLE_PROP_META_INHERIT)
477 return LV_STYLE_RES_INHERIT;
478 if(props[i] & LV_STYLE_PROP_META_INITIAL)
479 *value = lv_style_prop_get_default(prop_id);
480 else {
481 lv_style_value_t * values = (lv_style_value_t *)style->v_p.values_and_props;
482 *value = values[i];
483 }
484 return LV_STYLE_RES_FOUND;
485 }
486 }
487 }
488 else if(LV_STYLE_PROP_ID_MASK(style->prop1) == prop) {
489 if(style->prop1 & LV_STYLE_PROP_META_INHERIT)
490 return LV_STYLE_RES_INHERIT;
491 *value = (style->prop1 & LV_STYLE_PROP_META_INITIAL) ? lv_style_prop_get_default(LV_STYLE_PROP_ID_MASK(
492 style->prop1)) : style->v_p.value1;
493 return LV_STYLE_RES_FOUND;
494 }
495 return LV_STYLE_RES_NOT_FOUND;
496}
497
503bool lv_style_is_empty(const lv_style_t * style);
504
512
520
521#include "lv_style_gen.h"
522
523static inline void lv_style_set_size(lv_style_t * style, lv_coord_t value)
524{
525 lv_style_set_width(style, value);
526 lv_style_set_height(style, value);
527}
528
529static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value)
530{
531 lv_style_set_pad_left(style, value);
532 lv_style_set_pad_right(style, value);
533 lv_style_set_pad_top(style, value);
534 lv_style_set_pad_bottom(style, value);
535}
536
537static inline void lv_style_set_pad_hor(lv_style_t * style, lv_coord_t value)
538{
539 lv_style_set_pad_left(style, value);
540 lv_style_set_pad_right(style, value);
541}
542
543static inline void lv_style_set_pad_ver(lv_style_t * style, lv_coord_t value)
544{
545 lv_style_set_pad_top(style, value);
546 lv_style_set_pad_bottom(style, value);
547}
548
549static inline void lv_style_set_pad_gap(lv_style_t * style, lv_coord_t value)
550{
551 lv_style_set_pad_row(style, value);
552 lv_style_set_pad_column(style, value);
553}
554
565static inline bool lv_style_prop_has_flag(lv_style_prop_t prop, uint8_t flag)
566{
567 return _lv_style_prop_lookup_flags(prop) & flag;
568}
569
570/*************************
571 * GLOBAL VARIABLES
572 *************************/
573
574/**********************
575 * MACROS
576 **********************/
577
578#if LV_USE_ASSERT_STYLE
579# define LV_ASSERT_STYLE(style_p) \
580 do { \
581 LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \
582 LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); \
583 } while(0)
584#else
585# define LV_ASSERT_STYLE(p) do{}while(0)
586#endif
587
588#ifdef __cplusplus
589} /*extern "C"*/
590#endif
591
592#endif /*LV_STYLE_H*/
int32_t(* lv_anim_path_cb_t)(const struct _lv_anim_t *)
Definition lv_anim.h:46
void lv_style_set_prop_meta(lv_style_t *style, lv_style_prop_t prop, uint16_t meta)
#define LV_IMG_ZOOM_NONE
Definition lv_style.h:49
@ LV_BLEND_MODE_REPLACE
Definition lv_style.h:91
@ LV_BLEND_MODE_MULTIPLY
Definition lv_style.h:90
@ LV_BLEND_MODE_SUBTRACTIVE
Definition lv_style.h:89
@ LV_BLEND_MODE_ADDITIVE
Definition lv_style.h:88
@ LV_BLEND_MODE_NORMAL
Definition lv_style.h:87
lv_style_prop_t
Definition lv_style.h:178
uint8_t _lv_style_get_prop_group(lv_style_prop_t prop)
void lv_style_set_prop(lv_style_t *style, lv_style_prop_t prop, lv_style_value_t value)
uint8_t _lv_style_prop_lookup_flags(lv_style_prop_t prop)
void lv_style_init(lv_style_t *style)
bool lv_style_is_empty(const lv_style_t *style)
@ LV_BORDER_SIDE_INTERNAL
Definition lv_style.h:119
lv_style_res_t lv_style_get_prop(const lv_style_t *style, lv_style_prop_t prop, lv_style_value_t *value)
bool lv_style_remove_prop(lv_style_t *style, lv_style_prop_t prop)
lv_style_prop_t lv_style_get_num_custom_props(void)
lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop)
@ LV_DITHER_NONE
Definition lv_style.h:139
@ LV_DITHER_ORDERED
Definition lv_style.h:140
@ LV_DITHER_ERR_DIFF
Definition lv_style.h:141
@ LV_GRAD_DIR_VER
Definition lv_style.h:128
@ LV_GRAD_DIR_NONE
Definition lv_style.h:127
@ LV_GRAD_DIR_HOR
Definition lv_style.h:129
void lv_style_reset(lv_style_t *style)
Definition lv_style.h:155
lv_grad_dir_t dir
Definition lv_style.h:158
uint8_t stops_count
Definition lv_style.h:157
lv_dither_mode_t dither
Definition lv_style.h:160
Definition lv_style.h:149
lv_color_t color
Definition lv_style.h:150
uint8_t frac
Definition lv_style.h:151
Definition lv_style.h:310
Definition lv_style.h:318
Definition lv_style.h:297
uint32_t time
Definition lv_style.h:303
const lv_style_prop_t * props
Definition lv_style.h:298
uint32_t delay
Definition lv_style.h:304
lv_anim_path_cb_t path_xcb
Definition lv_style.h:302
Definition lv_style.h:167
const void * ptr
Definition lv_style.h:169
int32_t num
Definition lv_style.h:168
lv_color_t color
Definition lv_style.h:170