1 /**
2 * @file lv_grid.h
3 *
4 */
5
6 #ifndef LV_GRID_H
7 #define LV_GRID_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_GRID
18
19 /*********************
20 * DEFINES
21 *********************/
22 /**
23 * Can be used track size to make the track fill the free space.
24 * @param x how much space to take proportionally to other FR tracks
25 * @return a special track size
26 */
27 #define LV_GRID_FR(x) (LV_COORD_MAX - 100 + x)
28
29 #define LV_GRID_CONTENT (LV_COORD_MAX - 101)
30 LV_EXPORT_CONST_INT(LV_GRID_CONTENT);
31
32 #define LV_GRID_TEMPLATE_LAST (LV_COORD_MAX)
33 LV_EXPORT_CONST_INT(LV_GRID_TEMPLATE_LAST);
34
35 /**********************
36 * TYPEDEFS
37 **********************/
38
39 /*Can't include lv_obj.h because it includes this header file*/
40 struct _lv_obj_t;
41
42 typedef enum {
43 LV_GRID_ALIGN_START,
44 LV_GRID_ALIGN_CENTER,
45 LV_GRID_ALIGN_END,
46 LV_GRID_ALIGN_STRETCH,
47 LV_GRID_ALIGN_SPACE_EVENLY,
48 LV_GRID_ALIGN_SPACE_AROUND,
49 LV_GRID_ALIGN_SPACE_BETWEEN,
50 } lv_grid_align_t;
51
52 /**********************
53 * GLOBAL VARIABLES
54 **********************/
55
56 extern uint16_t LV_LAYOUT_GRID;
57 extern lv_style_prop_t LV_STYLE_GRID_COLUMN_DSC_ARRAY;
58 extern lv_style_prop_t LV_STYLE_GRID_COLUMN_ALIGN;
59 extern lv_style_prop_t LV_STYLE_GRID_ROW_DSC_ARRAY;
60 extern lv_style_prop_t LV_STYLE_GRID_ROW_ALIGN;
61 extern lv_style_prop_t LV_STYLE_GRID_CELL_COLUMN_POS;
62 extern lv_style_prop_t LV_STYLE_GRID_CELL_COLUMN_SPAN;
63 extern lv_style_prop_t LV_STYLE_GRID_CELL_X_ALIGN;
64 extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_POS;
65 extern lv_style_prop_t LV_STYLE_GRID_CELL_ROW_SPAN;
66 extern lv_style_prop_t LV_STYLE_GRID_CELL_Y_ALIGN;
67
68 /**********************
69 * GLOBAL PROTOTYPES
70 **********************/
71
72 void lv_grid_init(void);
73
74 void lv_obj_set_grid_dsc_array(lv_obj_t * obj, const lv_coord_t col_dsc[], const lv_coord_t row_dsc[]);
75
76 void lv_obj_set_grid_align(lv_obj_t * obj, lv_grid_align_t column_align, lv_grid_align_t row_align);
77
78 /**
79 * Set the cell of an object. The object's parent needs to have grid layout, else nothing will happen
80 * @param obj pointer to an object
81 * @param column_align the vertical alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH`
82 * @param col_pos column ID
83 * @param col_span number of columns to take (>= 1)
84 * @param row_align the horizontal alignment in the cell. `LV_GRID_START/END/CENTER/STRETCH`
85 * @param row_pos row ID
86 * @param row_span number of rows to take (>= 1)
87 */
88 void lv_obj_set_grid_cell(lv_obj_t * obj, lv_grid_align_t column_align, uint8_t col_pos, uint8_t col_span,
89 lv_grid_align_t row_align, uint8_t row_pos, uint8_t row_span);
90
91 /**
92 * Just a wrapper to `LV_GRID_FR` for bindings.
93 */
lv_grid_fr(uint8_t x)94 static inline lv_coord_t lv_grid_fr(uint8_t x)
95 {
96 return LV_GRID_FR(x);
97 }
98
99 void lv_style_set_grid_row_dsc_array(lv_style_t * style, const lv_coord_t value[]);
100 void lv_style_set_grid_column_dsc_array(lv_style_t * style, const lv_coord_t value[]);
101 void lv_style_set_grid_row_align(lv_style_t * style, lv_grid_align_t value);
102 void lv_style_set_grid_column_align(lv_style_t * style, lv_grid_align_t value);
103 void lv_style_set_grid_cell_column_pos(lv_style_t * style, lv_coord_t value);
104 void lv_style_set_grid_cell_column_span(lv_style_t * style, lv_coord_t value);
105 void lv_style_set_grid_cell_row_pos(lv_style_t * style, lv_coord_t value);
106 void lv_style_set_grid_cell_row_span(lv_style_t * style, lv_coord_t value);
107 void lv_style_set_grid_cell_x_align(lv_style_t * style, lv_coord_t value);
108 void lv_style_set_grid_cell_y_align(lv_style_t * style, lv_coord_t value);
109
110 void lv_obj_set_style_grid_row_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector);
111 void lv_obj_set_style_grid_column_dsc_array(lv_obj_t * obj, const lv_coord_t value[], lv_style_selector_t selector);
112 void lv_obj_set_style_grid_row_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector);
113 void lv_obj_set_style_grid_column_align(lv_obj_t * obj, lv_grid_align_t value, lv_style_selector_t selector);
114 void lv_obj_set_style_grid_cell_column_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
115 void lv_obj_set_style_grid_cell_column_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
116 void lv_obj_set_style_grid_cell_row_pos(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
117 void lv_obj_set_style_grid_cell_row_span(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
118 void lv_obj_set_style_grid_cell_x_align(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
119 void lv_obj_set_style_grid_cell_y_align(lv_obj_t * obj, lv_coord_t value, lv_style_selector_t selector);
120
lv_obj_get_style_grid_row_dsc_array(const lv_obj_t * obj,uint32_t part)121 static inline const lv_coord_t * lv_obj_get_style_grid_row_dsc_array(const lv_obj_t * obj, uint32_t part)
122 {
123 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_DSC_ARRAY);
124 return (const lv_coord_t *)v.ptr;
125 }
126
lv_obj_get_style_grid_column_dsc_array(const lv_obj_t * obj,uint32_t part)127 static inline const lv_coord_t * lv_obj_get_style_grid_column_dsc_array(const lv_obj_t * obj, uint32_t part)
128 {
129 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COLUMN_DSC_ARRAY);
130 return (const lv_coord_t *)v.ptr;
131 }
132
lv_obj_get_style_grid_row_align(const lv_obj_t * obj,uint32_t part)133 static inline lv_grid_align_t lv_obj_get_style_grid_row_align(const lv_obj_t * obj, uint32_t part)
134 {
135 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_ROW_ALIGN);
136 return (lv_grid_align_t)v.num;
137 }
138
lv_obj_get_style_grid_column_align(const lv_obj_t * obj,uint32_t part)139 static inline lv_grid_align_t lv_obj_get_style_grid_column_align(const lv_obj_t * obj, uint32_t part)
140 {
141 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_COLUMN_ALIGN);
142 return (lv_grid_align_t)v.num;
143 }
144
lv_obj_get_style_grid_cell_column_pos(const lv_obj_t * obj,uint32_t part)145 static inline lv_coord_t lv_obj_get_style_grid_cell_column_pos(const lv_obj_t * obj, uint32_t part)
146 {
147 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COLUMN_POS);
148 return (lv_coord_t)v.num;
149 }
150
lv_obj_get_style_grid_cell_column_span(const lv_obj_t * obj,uint32_t part)151 static inline lv_coord_t lv_obj_get_style_grid_cell_column_span(const lv_obj_t * obj, uint32_t part)
152 {
153 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_COLUMN_SPAN);
154 return (lv_coord_t)v.num;
155 }
156
lv_obj_get_style_grid_cell_row_pos(const lv_obj_t * obj,uint32_t part)157 static inline lv_coord_t lv_obj_get_style_grid_cell_row_pos(const lv_obj_t * obj, uint32_t part)
158 {
159 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_POS);
160 return (lv_coord_t)v.num;
161 }
162
lv_obj_get_style_grid_cell_row_span(const lv_obj_t * obj,uint32_t part)163 static inline lv_coord_t lv_obj_get_style_grid_cell_row_span(const lv_obj_t * obj, uint32_t part)
164 {
165 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_ROW_SPAN);
166 return (lv_coord_t)v.num;
167 }
168
lv_obj_get_style_grid_cell_x_align(const lv_obj_t * obj,uint32_t part)169 static inline lv_coord_t lv_obj_get_style_grid_cell_x_align(const lv_obj_t * obj, uint32_t part)
170 {
171 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_X_ALIGN);
172 return (lv_coord_t)v.num;
173 }
174
lv_obj_get_style_grid_cell_y_align(const lv_obj_t * obj,uint32_t part)175 static inline lv_coord_t lv_obj_get_style_grid_cell_y_align(const lv_obj_t * obj, uint32_t part)
176 {
177 lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_GRID_CELL_Y_ALIGN);
178 return (lv_coord_t)v.num;
179 }
180
181 /**********************
182 * GLOBAL VARIABLES
183 **********************/
184
185 /**********************
186 * MACROS
187 **********************/
188 #endif /*LV_USE_GRID*/
189
190 #ifdef __cplusplus
191 } /*extern "C"*/
192 #endif
193
194 #endif /*LV_GRID_H*/
195