add examples + refactoring

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-12 14:22:48 +01:00
parent e0fb0db735
commit 95b1bd8409
38 changed files with 622 additions and 583 deletions
+53 -43
View File
@@ -1,43 +1,53 @@
//#include "../../lv_examples.h"
//
///**
// * A simple row and a column layout with flexbox
// */
//void lv_example_flex_1(void)
//{
// /*Create a container with ROW flex direction*/
// lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont_row, 300, 75);
// lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
// lv_obj_set_flex_dir(cont_row, LV_FLEX_DIR_ROW);
// lv_obj_set_flex_gap(cont_row, 10);
//
// /*Create a container with COLUMN flex direction*/
// lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_size(cont_col, 200, 150);
// lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
// lv_obj_set_flex_dir(cont_col, LV_FLEX_DIR_COLUMN);
// lv_obj_set_flex_gap(cont_col, 10);
//
// uint32_t i;
// for(i = 0; i < 10; i++) {
// /*Add items to the row*/
// lv_obj_t * obj1 = lv_obj_create(cont_row, NULL);
// lv_obj_set_size(obj1, 100, LV_COORD_PCT(100));
// lv_obj_set_flex_item(obj1, true);
//
// lv_obj_t * label1 = lv_label_create(obj1, NULL);
// lv_label_set_text_fmt(label1, "Item: %d", i);
// lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0);
//
// /*Add items to the column*/
// lv_obj_t * obj2 = lv_obj_create(cont_col, NULL);
// lv_obj_set_size(obj2, LV_COORD_PCT(100), LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj2, true);
//
// lv_obj_t * label3 = lv_label_create(obj2, NULL);
// lv_label_set_text_fmt(label3, "Item: %d", i);
// lv_obj_align(label3, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_FLEX
/**
* A simple row and a column layout with flexbox
*/
void lv_example_flex_1(void)
{
static lv_flex_t flex_row;
lv_flex_init(&flex_row);
lv_flex_set_flow(&flex_row, LV_FLEX_FLOW_ROW);
static lv_flex_t flex_col;
lv_flex_init(&flex_col);
lv_flex_set_flow(&flex_col, LV_FLEX_FLOW_COLUMN);
/*Create a container with ROW flex direction*/
lv_obj_t * cont_row = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont_row, 300, 75);
lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5);
lv_obj_set_layout(cont_row, &flex_row);
/*Create a container with COLUMN flex direction*/
lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(cont_col, 200, 150);
lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_set_layout(cont_col, &flex_col);
uint32_t i;
for(i = 0; i < 10; i++) {
lv_obj_t * obj;
lv_obj_t * label;
/*Add items to the row*/
obj= lv_obj_create(cont_row, NULL);
lv_obj_set_size(obj, 100, LV_SIZE_PCT(100));
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "Item: %d", i);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
/*Add items to the column*/
obj = lv_obj_create(cont_col, NULL);
lv_obj_set_size(obj, LV_SIZE_PCT(100), LV_SIZE_CONTENT);
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "Item: %d", i);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
#endif
+30 -24
View File
@@ -1,24 +1,30 @@
//#include "../../lv_examples.h"
//
///**
// * Arrange items in column with wrap and place the row to get even space around them.
// */
//void lv_example_flex_2(void)
//{
// 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_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP);
// lv_obj_set_flex_place(cont, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START);
//
// uint32_t i;
// for(i = 0; i < 3; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_flex_item_place(obj, LV_FLEX_PLACE_STRETCH);
// lv_obj_set_size(obj, 70, LV_SIZE_AUTO);
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d", i);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_FLEX
/**
* Arrange items in rows with wrap and place the items to get even space around them.
*/
void lv_example_flex_2(void)
{
static lv_flex_t flex_row_wrap;
lv_flex_init(&flex_row_wrap);
lv_flex_set_flow(&flex_row_wrap, LV_FLEX_FLOW_ROW_WRAP);
lv_flex_set_place(&flex_row_wrap, LV_FLEX_PLACE_SPACE_EVENLY, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START);
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, &flex_row_wrap);
uint32_t i;
for(i = 0; i < 8; i++) {
lv_obj_t * obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
lv_obj_t * label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d", i);
}
}
#endif
+31 -30
View File
@@ -1,30 +1,31 @@
//#include "../../lv_examples.h"
//
///**
// * Arrange items in a row and demonstrate flex grow.
// */
//void lv_example_flex_3(void)
//{
// 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_flex_dir(cont, LV_FLEX_DIR_ROW);
//
// lv_obj_t * obj;
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 20, 20); /*Fix size*/
// lv_obj_set_flex_item(obj, true);
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_FLEX_GROW(1), 30); /*1 portion from the free space*/
// lv_obj_set_flex_item(obj, true);
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_FLEX_GROW(2), 40); /*2 portion from the free space*/
// lv_obj_set_flex_item(obj, true);
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/
// lv_obj_set_flex_item(obj, true);
//}
//
#include "../../../lvgl.h"
#if LV_USE_FLEX
/**
* Use a built in flex layout and demonstrate flex grow.
*/
void lv_example_flex_3(void)
{
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, &lv_flex_queue);
lv_obj_t * obj;
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 20, 20); /*Fix size*/
obj = lv_obj_create(cont, NULL);
lv_obj_set_height(obj, 30);
lv_obj_set_flex_grow(obj, 1); /*1 portion from the free space*/
obj = lv_obj_create(cont, NULL);
lv_obj_set_height(obj, 40);
lv_obj_set_flex_grow(obj, 2); /*2 portion from the free space*/
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/
}
#endif
+30 -24
View File
@@ -1,24 +1,30 @@
//#include "../../lv_examples.h"
//
///**
// * Reverse the order of flex items
// */
//void lv_example_flex_4(void)
//{
// 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_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP_REVERSE);
// lv_obj_set_flex_gap(cont, 10);
//
// uint32_t i;
// for(i = 0; i < 20; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 100, LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj, true);
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "Item: %d", i);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_FLEX
/**
* Reverse the order of flex items
*/
void lv_example_flex_4(void)
{
static lv_flex_t flex_col_rev;
lv_flex_init(&flex_col_rev);
lv_flex_set_flow(&flex_col_rev, LV_FLEX_FLOW_COLUMN_WRAP_REVERSE);
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, &flex_col_rev);
uint32_t i;
for(i = 0; i < 6; i++) {
lv_obj_t * obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 100, 30);
lv_obj_t * label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "Item: %d", i);
}
}
#endif
+52 -28
View File
@@ -1,28 +1,52 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate the effect of margin on flex item
// */
//void lv_example_flex_5(void)
//{
// 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_flex_dir(cont, LV_FLEX_DIR_ROW_WRAP);
//
// uint32_t i;
// for(i = 0; i < 20; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 100, LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj, true);
//
// /*Set margin on every side*/
// if(i == 4) {
// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 20);
// }
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "Item:%d", i);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_FLEX
static void row_gap_anim(lv_obj_t * obj, lv_anim_value_t v)
{
lv_obj_set_style_pad_row(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v);
}
static void column_gap_anim(lv_obj_t * obj, lv_anim_value_t v)
{
lv_obj_set_style_pad_column(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v);
}
/**
* Demonstrate the effect of column and row gap style properties
*/
void lv_example_flex_5(void)
{
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, &lv_flex_inline);
uint32_t i;
for(i = 0; i < 9; i++) {
lv_obj_t * obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
lv_obj_t * label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d", i);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, cont);
lv_anim_set_values(&a, 0, 10);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) row_gap_anim);
lv_anim_set_time(&a, 500);
lv_anim_set_playback_time(&a, 500);
lv_anim_start(&a);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) column_gap_anim);
lv_anim_set_time(&a, 3000);
lv_anim_set_playback_time(&a, 3000);
lv_anim_start(&a);
}
#endif
+27 -25
View File
@@ -1,25 +1,27 @@
//#include "../../lv_examples.h"
//
///**
// * RTL base direction changes order of the items.
// */
//void lv_example_flex_6(void)
//{
// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
// lv_obj_set_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP);
//
// uint32_t i;
// for(i = 0; i < 20; i++) {
// lv_obj_t * obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, 80, LV_SIZE_AUTO);
// lv_obj_set_flex_item(obj, true);
//
// lv_obj_t * label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d", i);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_FLEX
/**
* RTL base direction changes order of the items.
* Also demonstrate how horizontal scrolling works with RTL.
*/
void lv_example_flex_6(void)
{
lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL);
lv_obj_set_size(cont, 300, 220);
lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_layout(cont, &lv_flex_center_column);
uint32_t i;
for(i = 0; i < 20; i++) {
lv_obj_t * obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
lv_obj_t * label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d", i);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
#endif
+44 -39
View File
@@ -1,39 +1,44 @@
//#include "../../lv_examples.h"
//
///**
// * A simple grid
// */
//void lv_example_grid_1(void)
//{
// static lv_coord_t col_dsc[3] = {80, 80, 80};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*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_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
//
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1));
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "c%d, r%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_GRID
/**
* A simple grid
*/
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);
/*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_t * label;
lv_obj_t * obj;
uint32_t i;
for(i = 0; i < 9; i++) {
uint8_t col = i % 3;
uint8_t row = i / 3;
obj = lv_obj_create(cont, NULL);
/* Stretch the cell horizontally and vertically too
* Set span to 1 to make the cell 1 column/row sized */
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1,
LV_GRID_STRETCH, row, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "c%d, r%d", col, row);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
#endif
+68 -59
View File
@@ -1,59 +1,68 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate cell placement and span
// */
//void lv_example_grid_2(void)
//{
// static lv_coord_t col_dsc[3] = {80, 80, 80};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*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_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
//
// /*Cell to 0;0 and align to to the start (left/top) horizontally and vertically too */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(0, 1), LV_GRID_CELL_START(0, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c0, r0");
//
// /*Cell to 1;0 and align to to the start (left) horizontally and center vertically too */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(1, 1), LV_GRID_CELL_CENTER(0, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c1, r0");
//
// /*Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(2, 1), LV_GRID_CELL_END(0, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c2, r0");
//
// /*Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched. */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(1, 2), LV_GRID_CELL_STRETCH(1, 1));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c1-2, r1");
//
// /*Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched. */
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(0, 1), LV_GRID_CELL_STRETCH(1, 2));
// label = lv_label_create(obj, NULL);
// lv_label_set_text(label, "c0\nr1-2");
//}
//
#include "../../../lvgl.h"
#if LV_USE_GRID
/**
* Demonstrate cell placement and span
*/
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);
/*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_t * label;
lv_obj_t * obj;
/*Cell to 0;0 and align to to the start (left/top) horizontally and vertically too */
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_grid_cell(obj, LV_GRID_START, 0, 1,
LV_GRID_START, 0, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text(label, "c0, r0");
/*Cell to 1;0 and align to to the start (left) horizontally and center vertically too */
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_grid_cell(obj, LV_GRID_START, 1, 1,
LV_GRID_CENTER, 0, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text(label, "c1, r0");
/*Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too */
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_grid_cell(obj, LV_GRID_START, 2, 1,
LV_GRID_END, 0, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text(label, "c2, r0");
/*Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched. */
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, 1, 2,
LV_GRID_STRETCH, 1, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text(label, "c1-2, r1");
/*Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched. */
obj = lv_obj_create(cont, NULL);
lv_obj_set_size(obj, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, 0, 1,
LV_GRID_STRETCH, 1, 2);
label = lv_label_create(obj, NULL);
lv_label_set_text(label, "c0\nr1-2");
}
#endif
+49 -45
View File
@@ -1,45 +1,49 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate grid's "free unit"
// */
//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)};
//
// /* 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] = {60, LV_GRID_FR(1), 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*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_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1));
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_GRID
/**
* Demonstrate grid's "free unit"
*/
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)};
/* 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);
/*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_t * label;
lv_obj_t * obj;
uint32_t i;
for(i = 0; i < 9; i++) {
uint8_t col = i % 3;
uint8_t row = i / 3;
obj = lv_obj_create(cont, NULL);
/* Stretch the cell horizontally and vertically too
* Set span to 1 to make the cell 1 column/row sized */
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1,
LV_GRID_STRETCH, row, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d,%d", col, row);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
#endif
+45 -41
View File
@@ -1,41 +1,45 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate track placement
// */
//void lv_example_grid_4(void)
//{
// static lv_coord_t col_dsc[3] = {60, 60, 60};
// 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);
//
// /*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_size(cont, 300, 220);
// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0);
// lv_obj_set_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1));
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_GRID
/**
* Demonstrate track placement
*/
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_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_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;
uint32_t i;
for(i = 0; i < 9; i++) {
uint8_t col = i % 3;
uint8_t row = i / 3;
obj = lv_obj_create(cont, NULL);
/* Stretch the cell horizontally and vertically too
* Set span to 1 to make the cell 1 column/row sized */
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1,
LV_GRID_STRETCH, row, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d,%d", col, row);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
#endif
+67 -41
View File
@@ -1,41 +1,67 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate margin in grid
// */
//void lv_example_grid_5(void)
//{
//
// /*60x60 cells*/
// static lv_coord_t col_dsc[3] = {100, 60, 60};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// static lv_grid_t grid;
// lv_grid_init(&grid);
// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3);
//
// /*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_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 9; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(col, 1), LV_GRID_CELL_START(row, 1));
// lv_obj_set_size(obj, 55, 55);
// if(i == 1) {
// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 5);
// }
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_GRID
static void row_gap_anim(lv_obj_t * obj, lv_anim_value_t v)
{
lv_obj_set_style_pad_row(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v);
}
static void column_gap_anim(lv_obj_t * obj, lv_anim_value_t v)
{
lv_obj_set_style_pad_column(obj, LV_PART_MAIN, LV_STATE_DEFAULT, v);
}
/**
* Demonstrate margin in grid
*/
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);
/*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_t * label;
lv_obj_t * obj;
uint32_t i;
for(i = 0; i < 9; i++) {
uint8_t col = i % 3;
uint8_t row = i / 3;
obj = lv_obj_create(cont, NULL);
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1,
LV_GRID_STRETCH, row, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d,%d", col, row);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_var(&a, cont);
lv_anim_set_values(&a, 0, 10);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) row_gap_anim);
lv_anim_set_time(&a, 500);
lv_anim_set_playback_time(&a, 500);
lv_anim_start(&a);
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) column_gap_anim);
lv_anim_set_time(&a, 3000);
lv_anim_set_playback_time(&a, 3000);
lv_anim_start(&a);
}
#endif
+44 -43
View File
@@ -1,43 +1,44 @@
//#include "../../lv_examples.h"
//
///**
// * Demonstrate RTL direction on grid
// */
//void lv_example_grid_6(void)
//{
//
// static lv_coord_t col_dsc[3] = {100, 60, 60};
// static lv_coord_t row_dsc[3] = {60, 60, 60};
//
// 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)*/
//
// /*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_grid(cont, &grid);
//
// lv_obj_t * label;
// lv_obj_t * obj;
// uint32_t i;
// for(i = 0; i < 3; i++) {
// uint8_t col = i % 3;
// uint8_t row = i / 3;
//
// obj = lv_obj_create(cont, NULL);
// /* Stretch the cell horizontally and vertically too
// * Set span to 1 to make the cell 1 column/row sized */
// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_START(row, 1));
// lv_obj_set_size(obj, 55, 55);
//
// label = lv_label_create(obj, NULL);
// lv_label_set_text_fmt(label, "%d,%d", col, row);
// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
// }
//}
//
#include "../../../lvgl.h"
#if LV_USE_GRID
/**
* Demonstrate RTL direction on grid
*/
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);
/*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_t * label;
lv_obj_t * obj;
uint32_t i;
for(i = 0; i < 9; i++) {
uint8_t col = i % 3;
uint8_t row = i / 3;
obj = lv_obj_create(cont, NULL);
/* Stretch the cell horizontally and vertically too
* Set span to 1 to make the cell 1 column/row sized */
lv_obj_set_grid_cell(obj, LV_GRID_STRETCH, col, 1,
LV_GRID_STRETCH, row, 1);
label = lv_label_create(obj, NULL);
lv_label_set_text_fmt(label, "%d,%d", col, row);
lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);
}
}
#endif