1 #include "../../lv_examples.h"
2 #if LV_USE_GRID && LV_BUILD_EXAMPLES
3
4 /**
5 * A simple grid
6 */
lv_example_grid_1(void)7 void lv_example_grid_1(void)
8 {
9 static lv_coord_t col_dsc[] = {70, 70, 70, LV_GRID_TEMPLATE_LAST};
10 static lv_coord_t row_dsc[] = {50, 50, 50, LV_GRID_TEMPLATE_LAST};
11
12 /*Create a container with grid*/
13 lv_obj_t * cont = lv_obj_create(lv_scr_act());
14 lv_obj_set_style_grid_column_dsc_array(cont, col_dsc, 0);
15 lv_obj_set_style_grid_row_dsc_array(cont, row_dsc, 0);
16 lv_obj_set_size(cont, 300, 220);
17 lv_obj_center(cont);
18 lv_obj_set_layout(cont, LV_LAYOUT_GRID);
19
20 lv_obj_t * label;
21 lv_obj_t * obj;
22
23 uint32_t i;
24 for(i = 0; i < 9; i++) {
25 uint8_t col = i % 3;
26 uint8_t row = i / 3;
27
28 obj = lv_btn_create(cont);
29 /*Stretch the cell horizontally and vertically too
30 *Set span to 1 to make the cell 1 column/row sized*/
31 lv_obj_set_grid_cell(obj, LV_GRID_ALIGN_STRETCH, col, 1,
32 LV_GRID_ALIGN_STRETCH, row, 1);
33
34 label = lv_label_create(obj);
35 lv_label_set_text_fmt(label, "c%d, r%d", col, row);
36 lv_obj_center(label);
37 }
38 }
39
40 #endif
41