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

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

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

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

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

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

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