您尚未登录。

楼主 # 2024-11-05 21:10:59

memory
会员
注册时间: 2021-08-11
已发帖子: 482
积分: 458

LVGL 的 group 研究

初始化程序建立一个group,并把之设置为默认group

    lv_group_t * g = lv_group_create();
    lv_group_set_default(g);

创建输入设备后,把输入设备与该group关联:

    lv_indev_set_group(indev2, g);

离线

楼主 #1 2024-11-05 21:13:05

memory
会员
注册时间: 2021-08-11
已发帖子: 482
积分: 458

Re: LVGL 的 group 研究

多group 的 demo

lv_obj_t *btn1, *btn2, *btn3, *btn4;
lv_group_t* group1;
lv_group_t* group2;

void change_group_event_cb(lv_event_t* e)
{
    lv_indev_t * cur_drv = NULL;

    cur_drv = lv_indev_get_next(cur_drv);
    if(!cur_drv) {
    }

    lv_indev_set_group(cur_drv, group1);
    lv_group_focus_obj(btn1);
}

void init_multi_groups(void)
{
    // 创建第一个组的对象
    lv_obj_t* textarea1 = lv_textarea_create(lv_scr_act());
    lv_obj_set_size(textarea1, 200, 100);
    lv_obj_align(textarea1, LV_ALIGN_CENTER, -150, -100);

    btn1 = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn1, 100, 50);
    lv_obj_align(btn1, LV_ALIGN_CENTER, -150, 0);
    lv_obj_t *label1 = lv_label_create(btn1);
    lv_label_set_text(label1, "Button 1");

    btn2 = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn2, 100, 50);
    lv_obj_align(btn2, LV_ALIGN_CENTER, -150, 100);
    lv_obj_t *label2 = lv_label_create(btn2);
    lv_label_set_text(label2, "Button 2");

    // 创建第二个组的对象
    lv_obj_t* textarea2 = lv_textarea_create(lv_scr_act());
    lv_obj_set_size(textarea2, 200, 100);
    lv_obj_align(textarea2, LV_ALIGN_CENTER, 150, -100);

    btn3 = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn3, 100, 50);
    lv_obj_align(btn3, LV_ALIGN_CENTER, 150, 0);
    lv_obj_t *label3 = lv_label_create(btn3);
    lv_label_set_text(label3, "Button 3");

    btn4 = lv_btn_create(lv_scr_act());
    lv_obj_set_size(btn4, 100, 50);
    lv_obj_align(btn4, LV_ALIGN_CENTER, 150, 100);
    lv_obj_t *label4 = lv_label_create(btn4);
    lv_label_set_text(label4, "Button 4");

    // 创建两个输入设备组
    group1 = lv_group_create();
    lv_group_add_obj(group1, textarea1);
    lv_group_add_obj(group1, btn1);
    lv_group_add_obj(group1, btn2);

    group2 = lv_group_create();
    lv_group_add_obj(group2, textarea2);
    lv_group_add_obj(group2, btn3);
    lv_group_add_obj(group2, btn4);
    lv_obj_add_event_cb(btn4, change_group_event_cb, LV_EVENT_CLICKED, NULL);
    // 初始焦点设置到第一个组的第一个对象
    lv_indev_t * cur_drv = NULL;

    cur_drv = lv_indev_get_next(cur_drv);
    if(!cur_drv) {
    }
    lv_indev_set_group(cur_drv, group2);
    lv_group_focus_obj(textarea2);
}

这个demo默认焦点在 group2 上,点击btn4之后,默认焦点切换到group1。

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn