Navigating lv_menu with encoder

I’m working on a settings menu and the only input device I have is an encoder. The menu is created on a seperate screen and than switched in and out. I got sliders and buttons working and can select and actuate them using the encoder but labels are not selectable and therefore not clickable. Is this something I’m doing wrong or is this a limitation of the menu widget and labels??

Description

What MCU/Processor/Board and compiler are you using?

Nucleo F401RE running mbed OS 6

What do you want to achieve?

a settings menu using labels for navigation

What have you tried so far?

several examples with variing results

Code to reproduce

lv_obj_t * _menu = lv_menu_create(_menuScreen);
lv_menu_set_mode_root_back_btn(_menu, LV_MENU_ROOT_BACK_BTN_ENABLED);
v_obj_add_event_cb(_menu, btnEventHandler, LV_EVENT_CLICKED, _menu);
lv_obj_set_size(_menu, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL));
lv_obj_center(_menu);

lv_obj_t * label;
lv_obj_t * cont;
lv_group_t * group = lv_group_create();
lv_group_set_default(group);
lv_indev_set_group(encoderDriver, group);

lv_obj_t * sub_1_page = lv_menu_page_create(_menu, "Page 1");

cont = lv_menu_cont_create(sub_1_page);
label = lv_label_create(cont);
lv_label_set_text(label, "Hello, I am hiding here");

lv_obj_t * sub_2_page = lv_menu_page_create(_menu, "Page 2");

cont = lv_menu_cont_create(sub_2_page);
label = lv_label_create(cont);
lv_label_set_text(label, "Hello, I am hiding here");

// Create a main page
lv_obj_t * _mainPage = lv_menu_page_create(_menu, NULL);

lv_obj_t * section;
section = lv_menu_section_create(_menu);
//create_slider(section, "Kd", 0, 150, 120);
//create_slider(section, "Ki", 0, 150, 50);
//create_slider(section, "Kp", 0, 150, 80);

cont = lv_menu_cont_create(section);
label = lv_label_create(cont);
lv_label_set_text(label, "Item 1");
v_menu_set_load_page_event(menu, cont, sub_1_page);

cont = lv_menu_cont_create(section);
label = lv_label_create(cont);
lv_label_set_text(label, "Item 2");
v_menu_set_load_page_event(menu, cont, sub_2_page);

lv_menu_set_page(_menu, _mainPage);

Labels, and menu cont for that matter, are not automatically added to the default group on creation, so you can add the menu cont to the default group manually.

lv_group_add_obj(group, menu_cont);
lv_obj_clear_flag(menu_cont, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_add_flag(menu_cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);

Thanks for the suggestion I acctualy added the labels to a group but they were lost in the copy added here. In my tests the flags seemed to make no difference. So for now I tryed without them. And I found something is not working with the groups and several sceens at least in my implementation. Reducing the program to one screen helped and it seems to work but shows strange behavior.

Here I go. I have two labels and a slider. The focus on the slider works but on the labels the focus disappears. Rotating the encoder a few steps and the slider focuses again. :thinking: Counting the stepps of the encoder revealed that the focus works but the labels don’t change the style so it is merely not visible. :rofl: Maybe my problem with the seccond screen??

Further plaing around showed that pressing the encoder, when the focus is on one of the labels, switches from navigation to edit mode, as it should??? :face_with_raised_eyebrow: My expectation would have been that it “presses” the label and calls the sub page.

Even odder is the behaivior that now rotating the encoder one step is highlighting the label and the second step is finally calling the sub page. Please tell me that is not really intended behavior and but a
bug.:rofl:

As I see it now I have to write my own navigation routine using lv_group_set_focus_cb() or even my own state machine. Would be awesome if you know of some examples.

For completnes here my current test code:

group = lv_group_create();
    lv_group_set_default(group);
    lv_indev_set_group(encoderDriver, group);

    // // draw menu screen //
    _menu = lv_menu_create(lv_scr_act());
    lv_menu_set_mode_root_back_btn(_menu, LV_MENU_ROOT_BACK_BTN_ENABLED);
    lv_obj_add_event_cb(_menu, btnEventHandler, LV_EVENT_CLICKED, _menu);
    lv_obj_set_size(_menu, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL));
    lv_obj_center(_menu);
    
    lv_obj_t * sub_1_page = lv_menu_page_create(_menu, "Page 1");

    cont = lv_menu_cont_create(sub_1_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here on page 1");

    lv_obj_t * sub_2_page = lv_menu_page_create(_menu, "Page 2");

    cont = lv_menu_cont_create(sub_2_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here on page 2");

    // Create a main page
    _mainPage = lv_menu_page_create(_menu, NULL);

    cont = lv_menu_cont_create(_mainPage);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 1");
    lv_menu_set_load_page_event(_menu, cont, sub_1_page);

    lv_group_add_obj(group, cont);
    //lv_obj_clear_flag(cont, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);

    cont = lv_menu_cont_create(_mainPage);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 2");
    lv_menu_set_load_page_event(_menu, cont, sub_2_page);

    lv_group_add_obj(group, cont);
    lv_obj_add_flag(cont, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLLABLE);
    lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);

    cont = create_slider(_mainPage, "Kd", 0, 150, 120);

    lv_menu_set_page(_menu, _mainPage);

    lv_group_focus_next(group);

And the video of the behaivior:

Again thanks a lot for the pointer helped to not give up.

It gets even better :joy:

Counting the stepps of the encoder revealed that the focus works but the labels don’t change the style so it is merely not visible

Perhaps there isn’t a style to show that the cont is in focus.

I got your code working on my end, edited the default theme and made a pull request. Can you verify it works at least with the 1 screen?

Can confirm that it is working as expected. At least for 1 screen. Thanks a lot.

Now I will try to create a new sceen and test it there.