LVGL_多界面切换

LVGL_多界面切换

1、创建多个界面(create_page1();)
2、加载一个界面显示(lv_scr_load(page1);)
3、切换不同界面显示(lv_scr_load_anim(page2, LV_SCR_LOAD_ANIM_OVER_LEFT, 300, 0, false);)
LVGL_多界面切换_第1张图片

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;
}

你可能感兴趣的:(单片机UI人机界面,java,开发语言)