1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-21 06:53:01 +08:00
lvgl/examples/layouts/flex/lv_example_flex_1.c

45 lines
1.3 KiB
C
Raw Normal View History

2021-04-08 13:07:48 +02:00
#include "../../lv_examples.h"
2021-02-14 14:56:34 +01:00
#if LV_USE_FLEX && LV_BUILD_EXAMPLES
2021-02-12 14:22:48 +01:00
/**
* 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());
2021-02-12 14:22:48 +01:00
lv_obj_set_size(cont_row, 300, 75);
lv_obj_align(cont_row, LV_ALIGN_TOP_MID, 0, 5);
lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_ROW);
2021-02-12 14:22:48 +01:00
/*Create a container with COLUMN flex direction*/
lv_obj_t * cont_col = lv_obj_create(lv_scr_act());
2021-02-12 14:22:48 +01:00
lv_obj_set_size(cont_col, 200, 150);
lv_obj_align_to(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
lv_obj_set_flex_flow(cont_col, LV_FLEX_FLOW_COLUMN);
2021-02-12 14:22:48 +01:00
uint32_t i;
for(i = 0; i < 10; i++) {
lv_obj_t * obj;
lv_obj_t * label;
/*Add items to the row*/
2021-04-15 18:31:50 +02:00
obj= lv_btn_create(cont_row);
lv_obj_set_size(obj, 100, LV_PCT(100));
2021-02-12 14:22:48 +01:00
label = lv_label_create(obj);
2021-02-12 14:22:48 +01:00
lv_label_set_text_fmt(label, "Item: %d", i);
lv_obj_center(label);
2021-02-12 14:22:48 +01:00
/*Add items to the column*/
2021-04-15 18:31:50 +02:00
obj = lv_btn_create(cont_col);
lv_obj_set_size(obj, LV_PCT(100), LV_SIZE_CONTENT);
2021-02-12 14:22:48 +01:00
label = lv_label_create(obj);
2021-02-12 14:22:48 +01:00
lv_label_set_text_fmt(label, "Item: %d", i);
lv_obj_center(label);
2021-02-12 14:22:48 +01:00
}
}
#endif