LVGL_多界面切换
原文:https://blog.csdn.net/weixin_50183638/article/details/134223860
LVGL_多界面切换
1、创建多个界面(create_page1();)
2、加载一个界面显示(lv_scr_load(page1);)
3、切换不同界面显示(lv_scr_load_anim(page2, LV_SCR_LOAD_ANIM_OVER_LEFT, 300, 0, false);)
static lv_obj_t * page1;
static lv_obj_t * page2;
static void page1_gesture_event_handler(lv_event_t event)
{
if (event.code == LV_EVENT_CLICKED) {
lv_scr_load_anim(page2, LV_SCR_LOAD_ANIM_OVER_LEFT, 300, 0, false);
}
}
void create_page1(void)
{
// 创建页面1的内容
page1 = lv_obj_create(NULL);
lv_obj_set_size(page1, LV_HOR_RES, LV_VER_RES);
lv_obj_t * btn1 = lv_btn_create(page1);
lv_obj_set_pos(btn1, (LV_HOR_RES - 100) / 2, (LV_VER_RES - 50) / 2);
lv_obj_set_size(btn1, 150, 50);
lv_obj_t * label1 = lv_label_create(btn1);
lv_label_set_text(label1, "change page 2");
lv_obj_add_event_cb(btn1, page1_gesture_event_handler, LV_EVENT_ALL, NULL);
}
static void page2_gesture_event_handler(lv_event_t event)
{
if (event.code == LV_EVENT_CLICKED) {
lv_scr_load_anim(page1, LV_SCR_LOAD_ANIM_OVER_RIGHT, 1000, 0, false);
}
}
void create_page2(void)
{
// 创建页面2的内容
page2 = lv_obj_create(NULL);
lv_obj_set_size(page2, LV_HOR_RES, LV_VER_RES);
lv_obj_t * btn2 = lv_btn_create(page2);
lv_obj_set_pos(btn2, (LV_HOR_RES - 100) / 2, (LV_VER_RES - 50) / 2);
lv_obj_set_size(btn2, 150, 50);
lv_obj_t * label2 = lv_label_create(btn2);
lv_label_set_text(label2, "change page 1");
lv_obj_add_event_cb(btn2, page2_gesture_event_handler, LV_EVENT_ALL, NULL);
}
int main(void)
{
// 初始化LVGL库
lv_init();
create_page1();
create_page2();
// 显示页面1
lv_scr_load(page1);
while (1) {
lv_task_handler();
}
return 0;
}
————————————————
版权声明:本文为CSDN博主「HX科技」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_50183638/article/details/134223860