Description
I created menu-like object with lv_obj_create():
It has some items, each item has a label and switch.
But I could not figure out how to navigate this by using keypad.
For example, I want to use LV_KEY_LEFT or LV_KEY_RIGHT to select one of these items, and press LV_KEY_ENTER to enter the edit mode of the switch.
But for now, any key of LV_KEY_LEFT, LV_KEY_RIGHT and LV_KEY_ENTER only control state of the first switch, like:
What MCU/Processor/Board and compiler are you using?
lv_port_pc_vscode on Windows10
What LVGL version are you using?
V9.1
Code to reproduce
static void lv_setting_test(void)
{
lv_obj_t *menu = lv_obj_create(lv_scr_act());
lv_obj_set_size(menu, 300, 150);
lv_obj_set_align(menu, LV_ALIGN_CENTER);
lv_obj_set_scroll_snap_y(menu, LV_SCROLL_SNAP_CENTER);
lv_obj_set_flex_flow(menu, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_all(menu, 0, LV_PART_MAIN);
lv_obj_set_flex_align(menu, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_set_scroll_dir(menu, LV_DIR_VER);
lv_gridnav_add(menu, LV_GRIDNAV_CTRL_ROLLOVER);
lv_obj_t *item1 = lv_obj_create(menu);
lv_obj_set_size(item1, 300, 50);
lv_obj_set_flex_flow(item1, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(item1, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_clear_flag(item1, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t *label1 = lv_label_create(item1);
lv_label_set_text(label1, "Item 1");
lv_obj_set_flex_grow(label1, 5);
lv_obj_t *sw1 = lv_switch_create(item1);
lv_obj_remove_state(sw1, LV_STATE_FOCUSED);
lv_obj_set_flex_grow(sw1, 1);
lv_obj_t *item2 = lv_obj_create(menu);
lv_obj_set_size(item2, 300, 50);
lv_obj_set_flex_flow(item2, LV_FLEX_FLOW_ROW);
lv_obj_set_flex_align(item2, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
lv_obj_clear_flag(item2, LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t *label2 = lv_label_create(item2);
lv_label_set_text(label2, "Item 2");
lv_obj_set_flex_grow(label2, 5);
lv_obj_t *sw2 = lv_switch_create(item2);
lv_obj_remove_state(sw2, LV_STATE_FOCUSED);
lv_obj_set_flex_grow(sw2, 1);