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_2.c

36 lines
1.0 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
/**
* Arrange items in rows with wrap and place the items to get even space around them.
*/
void lv_example_flex_2(void)
{
static lv_style_t style;
lv_style_init(&style);
lv_style_set_flex_flow(&style, LV_FLEX_FLOW_ROW_WRAP);
lv_style_set_flex_main_place(&style, LV_FLEX_ALIGN_SPACE_EVENLY);
lv_style_set_layout(&style, LV_LAYOUT_FLEX);
2021-02-12 14:22:48 +01:00
lv_obj_t * cont = lv_obj_create(lv_scr_act());
2021-02-12 14:22:48 +01:00
lv_obj_set_size(cont, 300, 220);
lv_obj_center(cont);
lv_obj_add_style(cont, &style, 0);
2021-12-17 11:17:30 +01:00
lv_group_add_obj(lv_group_get_default(), cont);
lv_obj_set_style_bg_color(cont, lv_color_hex(0xffaabb), LV_STATE_FOCUSED);
lv_gridfocus_add(cont, 0);
2021-02-12 14:22:48 +01:00
unsigned int i;
2021-12-17 11:17:30 +01:00
for(i = 0; i < 23; i++) {
lv_obj_t * obj = lv_btn_create(cont);
2021-02-12 14:22:48 +01:00
lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
lv_obj_t * label = lv_label_create(obj);
lv_label_set_text_fmt(label, "%u", i);
lv_obj_center(label);
2021-02-12 14:22:48 +01:00
}
}
#endif