1 /**
2 * @file lv_flex.h
3 *
4 */
5
6 #ifndef LV_FLEX_H
7 #define LV_FLEX_H
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 /*********************
14 * INCLUDES
15 *********************/
16 #include "../../../core/lv_obj.h"
17 #if LV_USE_FLEX
18
19 /*********************
20 * DEFINES
21 *********************/
22
23 #define LV_OBJ_FLAG_FLEX_IN_NEW_TRACK LV_OBJ_FLAG_LAYOUT_1
24 LV_EXPORT_CONST_INT(LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
25
26 #define _LV_FLEX_COLUMN (1 << 0)
27 #define _LV_FLEX_WRAP (1 << 2)
28 #define _LV_FLEX_REVERSE (1 << 3)
29
30 /**********************
31 * TYPEDEFS
32 **********************/
33
34 /*Can't include lv_obj.h because it includes this header file*/
35 struct _lv_obj_t;
36
37 typedef enum {
38 LV_FLEX_ALIGN_START,
39 LV_FLEX_ALIGN_END,
40 LV_FLEX_ALIGN_CENTER,
41 LV_FLEX_ALIGN_SPACE_EVENLY,
42 LV_FLEX_ALIGN_SPACE_AROUND,
43 LV_FLEX_ALIGN_SPACE_BETWEEN,
44 } lv_flex_align_t;
45
46 typedef enum {
47 LV_FLEX_FLOW_ROW = 0x00,
48 LV_FLEX_FLOW_COLUMN = _LV_FLEX_COLUMN,
49 LV_FLEX_FLOW_ROW_WRAP = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP,
50 LV_FLEX_FLOW_ROW_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_REVERSE,
51 LV_FLEX_FLOW_ROW_WRAP_REVERSE = LV_FLEX_FLOW_ROW | _LV_FLEX_WRAP | _LV_FLEX_REVERSE,
52 LV_FLEX_FLOW_COLUMN_WRAP = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP,
53 LV_FLEX_FLOW_COLUMN_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_REVERSE,
54 LV_FLEX_FLOW_COLUMN_WRAP_REVERSE = LV_FLEX_FLOW_COLUMN | _LV_FLEX_WRAP | _LV_FLEX_REVERSE,
55 } lv_flex_flow_t;
56
57 /**********************
58 * GLOBAL VARIABLES
59 **********************/
60 extern uint32_t LV_LAYOUT_FLEX;
61 extern lv_style_prop_t LV_STYLE_FLEX_FLOW;
62 extern lv_style_prop_t LV_STYLE_FLEX_MAIN_PLACE;
63 extern lv_style_prop_t LV_STYLE_FLEX_CROSS_PLACE;
64 extern lv_style_prop_t LV_STYLE_FLEX_TRACK_PLACE;
65 extern lv_style_prop_t LV_STYLE_FLEX_GROW;
66
67 /**********************
68 * GLOBAL PROTOTYPES
69 **********************/
70
71 /**
72 * Initialize a flex layout the default values
73 * @param flex pointer to a flex layout descriptor
74 */
75 void lv_flex_init(void);
76
77 /**
78 * Set hot the item should flow
79 * @param flex pointer to a flex layout descriptor
80 * @param flow an element of `lv_flex_flow_t`.
81 */
82 void lv_obj_set_flex_flow(lv_obj_t * obj, lv_flex_flow_t flow);
83
84 /**
85 * Set how to place (where to align) the items and tracks
86 * @param flex pointer: to a flex layout descriptor
87 * @param main_place where to place the items on main axis (in their track). Any value of `lv_flex_align_t`.
88 * @param cross_place where to place the item in their track on the cross axis. `LV_FLEX_ALIGN_START/END/CENTER`
89 * @param track_place where to place the tracks in the cross direction. Any value of `lv_flex_align_t`.
90 */
91 void lv_obj_set_flex_align(lv_obj_t * obj, lv_flex_align_t main_place, lv_flex_align_t cross_place,
92 lv_flex_align_t track_cross_place);
93
94 /**
95 * Sets the width or height (on main axis) to grow the object in order fill the free space
96 * @param obj pointer to an object. The parent must have flex layout else nothing will happen.
97 * @param grow a value to set how much free space to take proportionally to other growing items.
98 */
99 void lv_obj_set_flex_grow(lv_obj_t * obj, uint8_t grow);
100
101 void lv_style_set_flex_flow(lv_style_t * style, lv_flex_flow_t value);
102 void lv_style_set_flex_main_place(lv_style_t * style, lv_flex_align_t value);
103 void lv_style_set_flex_cross_place(lv_style_t * style, lv_flex_align_t value);
104 void lv_style_set_flex_track_place(lv_style_t * style, lv_flex_align_t value);
105 void lv_style_set_flex_grow(lv_style_t * style, uint8_t value);
106 void lv_obj_set_style_flex_flow(lv_obj_t * obj, lv_flex_flow_t value, lv_style_selector_t selector);
107 void lv_obj_set_style_flex_main_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector);
108 void lv_obj_set_style_flex_cross_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector);
109 void lv_obj_set_style_flex_track_place(lv_obj_t * obj, lv_flex_align_t value, lv_style_selector_t selector);
110 void lv_obj_set_style_flex_grow(lv_obj_t * obj, uint8_t value, lv_style_selector_t selector);
111
lv_obj_get_style_flex_flow(const lv_obj_t * obj,uint32_t part)112 static inline lv_flex_flow_t lv_obj_get_style_flex_flow(const lv_obj_t * obj, uint32_t part)
113 {
114 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_FLOW);
115 return (lv_flex_flow_t)v.num;
116 }
117
lv_obj_get_style_flex_main_place(const lv_obj_t * obj,uint32_t part)118 static inline lv_flex_align_t lv_obj_get_style_flex_main_place(const lv_obj_t * obj, uint32_t part)
119 {
120 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_MAIN_PLACE);
121 return (lv_flex_align_t)v.num;
122 }
123
lv_obj_get_style_flex_cross_place(const lv_obj_t * obj,uint32_t part)124 static inline lv_flex_align_t lv_obj_get_style_flex_cross_place(const lv_obj_t * obj, uint32_t part)
125 {
126 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_CROSS_PLACE);
127 return (lv_flex_align_t)v.num;
128 }
129
lv_obj_get_style_flex_track_place(const lv_obj_t * obj,uint32_t part)130 static inline lv_flex_align_t lv_obj_get_style_flex_track_place(const lv_obj_t * obj, uint32_t part)
131 {
132 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_TRACK_PLACE);
133 return (lv_flex_align_t)v.num;
134 }
135
lv_obj_get_style_flex_grow(const lv_obj_t * obj,uint32_t part)136 static inline uint8_t lv_obj_get_style_flex_grow(const lv_obj_t * obj, uint32_t part)
137 {
138 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_FLEX_GROW);
139 return (uint8_t)v.num;
140 }
141
142
143 /**********************
144 * MACROS
145 **********************/
146
147 #endif /*LV_USE_FLEX*/
148
149 #ifdef __cplusplus
150 } /*extern "C"*/
151 #endif
152
153 #endif /*LV_FLEX_H*/
154