How to navigate in menu cont?

I just started checking out LVGL to see if we can use it and ran into a similar problem. It seems like the menu cont is not implemented with keyboard/encoder navigation option. I did some debugging and got it working.

Firs of all, the menu_cont is not added to the default group automatically. To add it to all menu conts you can add .group_def to lv_menu_cont_class in lv_menu.c

const lv_obj_class_t lv_menu_cont_class = {
    .constructor_cb = lv_menu_cont_constructor,
    .base_class = &lv_obj_class,
    .width_def = LV_PCT(100),
    .height_def = LV_SIZE_CONTENT,
    .group_def = LV_OBJ_CLASS_GROUP_DEF_TRUE
};

You can also add it manually with lv_group_add_obj for all conts you’d like to include:

    g = lv_group_create();
    lv_group_set_default(g);

    lv_indev_t* cur_drv = NULL;
    for (;;) {
        cur_drv = lv_indev_get_next(cur_drv);
        if (!cur_drv) {
            break;
        }

        if (cur_drv->driver->type == LV_INDEV_TYPE_KEYPAD) {
            lv_indev_set_group(cur_drv, g);
        }

        if (cur_drv->driver->type == LV_INDEV_TYPE_ENCODER) {
            lv_indev_set_group(cur_drv, g);
        }
    }


cont = lv_menu_cont_create(_mainPage);
lv_group_add_obj(g, cont);

After this, it should be able to navigate in the menu, but you will not see what is in focus, which makes it a bit hard…
To at least see what is selected you could just add
lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
in lv_theme_default.c

    else if(lv_obj_check_type(obj, &lv_menu_cont_class)) {
        lv_obj_add_style(obj, &styles->menu_cont, 0);
        lv_obj_add_style(obj, &styles->menu_pressed, LV_STATE_PRESSED);
        lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_STATE_PRESSED | LV_STATE_CHECKED);
        lv_obj_add_style(obj, &styles->bg_color_primary_muted, LV_STATE_CHECKED);
        lv_obj_add_style(obj, &styles->outline_primary, LV_STATE_FOCUS_KEY);
    }

Then you should get blue lines around what is selected. To make it look good and work more smooth, you will have to do some other modifications as well, but this was as far as I got in my investigation. I guess it’s probably better to change the background color when in focus. I’m new to LVGL, so there may be better solutions to this.