#if 1
static void event_cb(lv_event_t * e)
{
/*The original target of the event. Can be the buttons or the container*/
lv_obj_t * target = lv_event_get_target(e);
/*The current target is always the container as the event is added to it*/
lv_obj_t * cont = lv_event_get_current_target(e);
lv_obj_set_style_bg_color(target, lv_palette_main(LV_PALETTE_RED) ,0);//LV_PALETTE_GREEN LV_PALETTE_RED
}
/**
* Demonstrate event bubbling
*/
void lv_100ask_demo_course_2_1_1(void)
{
lv_obj_t * cont = lv_obj_create(lv_scr_act());
lv_obj_set_size(cont, 290, 200);
lv_obj_center(cont);
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP); //给父组件设置弹性布局使用函数接口 ,排成一排
lv_obj_set_style_bg_color(cont, lv_palette_main(LV_PALETTE_BLUE) ,0);
uint32_t i;
for(i = 0; i < 30; i++) {
lv_obj_t * btn = lv_btn_create(cont);
lv_obj_set_size(btn, 80, 50);
lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE);
lv_obj_set_style_bg_color(btn, lv_palette_main(LV_PALETTE_YELLOW) ,0);
// lv_obj_add_flag(btn, LV_OBJ_FLAG_EVENT_BUBBLE);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
lv_obj_center(label);
}
lv_obj_add_event_cb(cont, event_cb, LV_EVENT_PRESSED, NULL);
}
#endif
15 lvgl 弹性布局,按键按下变色效果
最新推荐文章于 2024-09-01 09:37:14 发布