1 /**
2 * @file lv_obj_style.h
3 *
4 */
5
6 #ifndef LV_OBJ_STYLE_H
7 #define LV_OBJ_STYLE_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #include <stdint.h>
17 #include <stdbool.h>
18 #include "../misc/lv_bidi.h"
19
20 /*********************
21 * DEFINES
22 *********************/
23
24 /**********************
25 * TYPEDEFS
26 **********************/
27 /*Can't include lv_obj.h because it includes this header file*/
28 struct _lv_obj_t;
29
30 typedef enum {
31 _LV_STYLE_STATE_CMP_SAME, /*The style properties in the 2 states are identical*/
32 _LV_STYLE_STATE_CMP_DIFF_REDRAW, /*The differences can be shown with a simple redraw*/
33 _LV_STYLE_STATE_CMP_DIFF_DRAW_PAD, /*The differences can be shown with a simple redraw*/
34 _LV_STYLE_STATE_CMP_DIFF_LAYOUT, /*The differences can be shown with a simple redraw*/
35 } _lv_style_state_cmp_t;
36
37 typedef uint32_t lv_style_selector_t;
38
39 typedef struct {
40 lv_style_t * style;
41 uint32_t selector : 24;
42 uint32_t is_local : 1;
43 uint32_t is_trans : 1;
44 } _lv_obj_style_t;
45
46 typedef struct {
47 uint16_t time;
48 uint16_t delay;
49 lv_style_selector_t selector;
50 lv_style_prop_t prop;
51 lv_anim_path_cb_t path_cb;
52 #if LV_USE_USER_DATA
53 void * user_data;
54 #endif
55 } _lv_obj_style_transition_dsc_t;
56
57 /**********************
58 * GLOBAL PROTOTYPES
59 **********************/
60
61 /**
62 * Initialize the object related style manager module.
63 * Called by LVGL in `lv_init()`
64 */
65 void _lv_obj_style_init(void);
66
67 /**
68 * Add a style to an object.
69 * @param obj pointer to an object
70 * @param style pointer to a style to add
71 * @param selector OR-ed value of parts and state to which the style should be added
72 * @example lv_obj_add_style(btn, &style_btn, 0); //Default button style
73 * @example lv_obj_add_style(btn, &btn_red, LV_STATE_PRESSED); //Overwrite only some colors to red when pressed
74 */
75 void lv_obj_add_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector);
76
77 /**
78 * Add a style to an object.
79 * @param obj pointer to an object
80 * @param style pointer to a style to remove. Can be NULL to check only the selector
81 * @param selector OR-ed values of states and a part to remove only styles with matching selectors. LV_STATE_ANY and LV_PART_ANY can be used
82 * @example lv_obj_remove_style(obj, &style, LV_PART_ANY | LV_STATE_ANY); //Remove a specific style
83 * @example lv_obj_remove_style(obj, NULL, LV_PART_MAIN | LV_STATE_ANY); //Remove all styles from the main part
84 * @example lv_obj_remove_style(obj, NULL, LV_PART_ANY | LV_STATE_ANY); //Remove all styles
85 */
86 void lv_obj_remove_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector);
87
88 /**
89 * Remove all styles from an object
90 * @param obj pointer to an object
91 */
lv_obj_remove_style_all(struct _lv_obj_t * obj)92 static inline void lv_obj_remove_style_all(struct _lv_obj_t * obj)
93 {
94 lv_obj_remove_style(obj, NULL, LV_PART_ANY | LV_STATE_ANY);
95 }
96
97 /**
98 * Notify all object if a style is modified
99 * @param style pointer to a style. Only the objects with this style will be notified
100 * (NULL to notify all objects)
101 */
102 void lv_obj_report_style_change(lv_style_t * style);
103
104 /**
105 * Notify an object and its children about its style is modified.
106 * @param obj pointer to an object
107 * @param part the part whose style was changed. E.g. `LV_PART_ANY`, `LV_PART_MAIN`
108 * @param prop `LV_STYLE_PROP_ANY` or an `LV_STYLE_...` property.
109 * It is used to optimize what needs to be refreshed.
110 * `LV_STYLE_PROP_INV` to perform only a style cache update
111 */
112 void lv_obj_refresh_style(struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop);
113
114 /**
115 * Enable or disable automatic style refreshing when a new style is added/removed to/from an object
116 * or any other style change happens.
117 * @param en true: enable refreshing; false: disable refreshing
118 */
119 void lv_obj_enable_style_refresh(bool en);
120
121 /**
122 * Get the value of a style property. The current state of the object will be considered.
123 * Inherited properties will be inherited.
124 * If a property is not set a default value will be returned.
125 * @param obj pointer to an object
126 * @param part a part from which the property should be get
127 * @param prop the property to get
128 * @return the value of the property.
129 * Should be read from the correct field of the `lv_style_value_t` according to the type of the property.
130 */
131 lv_style_value_t lv_obj_get_style_prop(const struct _lv_obj_t * obj, lv_part_t part, lv_style_prop_t prop);
132
133 /**
134 * Set local style property on an object's part and state.
135 * @param obj pointer to an object
136 * @param prop the property
137 * @param value value of the property. The correct element should be set according to the type of the property
138 * @param selector OR-ed value of parts and state for which the style should be set
139 */
140 void lv_obj_set_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t value,
141 lv_style_selector_t selector);
142
143 void lv_obj_set_local_style_prop_meta(struct _lv_obj_t * obj, lv_style_prop_t prop, uint16_t meta,
144 lv_style_selector_t selector);
145
146 lv_style_res_t lv_obj_get_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_value_t * value,
147 lv_style_selector_t selector);
148
149 /**
150 * Remove a local style property from a part of an object with a given state.
151 * @param obj pointer to an object
152 * @param prop a style property to remove.
153 * @param selector OR-ed value of parts and state for which the style should be removed
154 * @return true the property was found and removed; false: the property was not found
155 */
156 bool lv_obj_remove_local_style_prop(struct _lv_obj_t * obj, lv_style_prop_t prop, lv_style_selector_t selector);
157
158 /**
159 * Used internally for color filtering
160 */
161 lv_style_value_t _lv_obj_style_apply_color_filter(const struct _lv_obj_t * obj, uint32_t part, lv_style_value_t v);
162
163 /**
164 * Used internally to create a style transition
165 * @param obj
166 * @param part
167 * @param prev_state
168 * @param new_state
169 * @param tr
170 */
171 void _lv_obj_style_create_transition(struct _lv_obj_t * obj, lv_part_t part, lv_state_t prev_state,
172 lv_state_t new_state, const _lv_obj_style_transition_dsc_t * tr);
173
174 /**
175 * Used internally to compare the appearance of an object in 2 states
176 * @param obj
177 * @param state1
178 * @param state2
179 * @return
180 */
181 _lv_style_state_cmp_t _lv_obj_style_state_compare(struct _lv_obj_t * obj, lv_state_t state1, lv_state_t state2);
182
183 /**
184 * Fade in an an object and all its children.
185 * @param obj the object to fade in
186 * @param time time of fade
187 * @param delay delay to start the animation
188 */
189 void lv_obj_fade_in(struct _lv_obj_t * obj, uint32_t time, uint32_t delay);
190
191 /**
192 * Fade out an an object and all its children.
193 * @param obj the object to fade out
194 * @param time time of fade
195 * @param delay delay to start the animation
196 */
197 void lv_obj_fade_out(struct _lv_obj_t * obj, uint32_t time, uint32_t delay);
198
199 lv_state_t lv_obj_style_get_selector_state(lv_style_selector_t selector);
200
201 lv_part_t lv_obj_style_get_selector_part(lv_style_selector_t selector);
202
203 #include "lv_obj_style_gen.h"
204
lv_obj_set_style_pad_all(struct _lv_obj_t * obj,lv_coord_t value,lv_style_selector_t selector)205 static inline void lv_obj_set_style_pad_all(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector)
206 {
207 lv_obj_set_style_pad_left(obj, value, selector);
208 lv_obj_set_style_pad_right(obj, value, selector);
209 lv_obj_set_style_pad_top(obj, value, selector);
210 lv_obj_set_style_pad_bottom(obj, value, selector);
211 }
212
lv_obj_set_style_pad_hor(struct _lv_obj_t * obj,lv_coord_t value,lv_style_selector_t selector)213 static inline void lv_obj_set_style_pad_hor(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector)
214 {
215 lv_obj_set_style_pad_left(obj, value, selector);
216 lv_obj_set_style_pad_right(obj, value, selector);
217 }
218
lv_obj_set_style_pad_ver(struct _lv_obj_t * obj,lv_coord_t value,lv_style_selector_t selector)219 static inline void lv_obj_set_style_pad_ver(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector)
220 {
221 lv_obj_set_style_pad_top(obj, value, selector);
222 lv_obj_set_style_pad_bottom(obj, value, selector);
223 }
224
lv_obj_set_style_pad_gap(struct _lv_obj_t * obj,lv_coord_t value,lv_style_selector_t selector)225 static inline void lv_obj_set_style_pad_gap(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector)
226 {
227 lv_obj_set_style_pad_row(obj, value, selector);
228 lv_obj_set_style_pad_column(obj, value, selector);
229 }
230
lv_obj_set_style_size(struct _lv_obj_t * obj,lv_coord_t value,lv_style_selector_t selector)231 static inline void lv_obj_set_style_size(struct _lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector)
232 {
233 lv_obj_set_style_width(obj, value, selector);
234 lv_obj_set_style_height(obj, value, selector);
235 }
236
237 lv_text_align_t lv_obj_calculate_style_text_align(const struct _lv_obj_t * obj, lv_part_t part, const char * txt);
238
lv_obj_get_style_transform_zoom_safe(const struct _lv_obj_t * obj,uint32_t part)239 static inline lv_coord_t lv_obj_get_style_transform_zoom_safe(const struct _lv_obj_t * obj, uint32_t part)
240 {
241 int16_t zoom = lv_obj_get_style_transform_zoom(obj, part);
242 return zoom != 0 ? zoom : 1;
243 }
244
245
246 /**
247 * Get the `opa` style property from all parents and multiply and `>> 8` them.
248 * @param obj the object whose opacity should be get
249 * @param part the part whose opacity should be get. Non-MAIN parts will consider the `opa` of teh MAIN part too
250 * @return the final opacity considering the parents' opacity too
251 */
252 lv_opa_t lv_obj_get_style_opa_recursive(const struct _lv_obj_t * obj, lv_part_t part);
253
254
255 /**********************
256 * MACROS
257 **********************/
258
259 #ifdef __cplusplus
260 } /*extern "C"*/
261 #endif
262
263 #endif /*LV_OBJ_STYLE_H*/
264