feat(style): store layout and position coordinates as style properties

related to #2152
This commit is contained in:
Gabor Kiss-Vamosi
2021-03-23 20:51:39 +01:00
parent 7cc3ed51bf
commit b7becbbb22
71 changed files with 1247 additions and 882 deletions

View File

@@ -6,18 +6,16 @@
*/
void lv_example_grid_1(void)
{
static lv_coord_t col_dsc[3] = {70, 70, 70};
static lv_coord_t row_dsc[3] = {50, 50, 50};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
static lv_coord_t col_dsc[] = {70, 70, 70, LV_COORD_MAX};
static lv_coord_t row_dsc[] = {50, 50, 50, LV_COORD_MAX};
/*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_style_grid_column_template(cont, LV_PART_MAIN, LV_STATE_DEFAULT, col_dsc);
lv_obj_set_style_grid_row_template(cont, LV_PART_MAIN, LV_STATE_DEFAULT, row_dsc);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_set_layout(cont, LV_LAYOUT_GRID);
lv_obj_t * label;
lv_obj_t * obj;

View File

@@ -7,18 +7,14 @@
*/
void lv_example_grid_2(void)
{
static lv_coord_t col_dsc[3] = {70, 70, 70};
static lv_coord_t row_dsc[3] = {50, 50, 50};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
static lv_coord_t col_dsc[] = {70, 70, 70, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[] = {50, 50, 50, LV_GRID_TEMPLATE_LAST};
/*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_t * label;
lv_obj_t * obj;

View File

@@ -9,22 +9,18 @@ void lv_example_grid_3(void)
/*Column 1: fix width 60 px
*Column 2: 1 unit from the remaining free space
*Column 3: 2 unit from the remaining free space*/
static lv_coord_t col_dsc[3] = {60, LV_GRID_FR(1), LV_GRID_FR(2)};
static lv_coord_t col_dsc[] = {60, LV_GRID_FR(1), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
/*Row 1: fix width 60 px
*Row 2: 1 unit from the remaining free space
*Row 3: fix width 60 px*/
static lv_coord_t row_dsc[3] = {40, LV_GRID_FR(1), 40};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
static lv_coord_t row_dsc[] = {40, LV_GRID_FR(1), 40, LV_GRID_TEMPLATE_LAST};
/*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_t * label;
lv_obj_t * obj;

View File

@@ -6,21 +6,18 @@
*/
void lv_example_grid_4(void)
{
static lv_coord_t col_dsc[3] = {60, 60, 60};
static lv_coord_t row_dsc[3] = {40, 40, 40};
static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
/*Add space between the columns and move the rows to the bottom (end)*/
lv_grid_set_place(&grid, LV_GRID_SPACE_BETWEEN, LV_GRID_END);
/*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_grid_place(cont, LV_GRID_SPACE_BETWEEN, LV_GRID_END);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_t * label;
lv_obj_t * obj;

View File

@@ -18,18 +18,14 @@ void lv_example_grid_5(void)
{
/*60x60 cells*/
static lv_coord_t col_dsc[3] = {60, 60, 60};
static lv_coord_t row_dsc[3] = {40, 40, 40};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST};
/*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &grid);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_t * label;
lv_obj_t * obj;

View File

@@ -7,19 +7,15 @@
void lv_example_grid_6(void)
{
static lv_coord_t col_dsc[3] = {60, 60, 60};
static lv_coord_t row_dsc[3] = {40, 40, 40};
static lv_grid_t grid;
lv_grid_init(&grid);
lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
static lv_coord_t col_dsc[] = {60, 60, 60, LV_GRID_TEMPLATE_LAST};
static lv_coord_t row_dsc[] = {40, 40, 40, LV_GRID_TEMPLATE_LAST};
/*Create a container with grid*/
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
lv_obj_set_layout(cont, &grid);
lv_obj_set_grid_template(cont, col_dsc, row_dsc);
lv_obj_t * label;
lv_obj_t * obj;