Description
I have set up LVGL on a custom board. I have 4 buttons available and have configured three of them as an encoder. I have a 4th button, set up as “Esc”, which must be a back/cancel button.
I have two lists, each have their own group, the first of which is my main menu. When I click on a button in the main menu list, I freeze the focus of that group, then I populate the second group with items depending on which button was clicked in the main menu. I can then focus and scroll through the second list.
I cant find a way to get back to the main menu group after clicking my “Back” button.
What MCU/Processor/Board and compiler are you using?
I am using a custom board based off of the STM32F769 chip. I am compiling in CubeIDE (Eclipse).
What LVGL version are you using?
V8.1
What do you want to achieve?
What I want to achieve is a way of getting back to the main menu (i.e. delete the sub-menu group and unfreeze the main menu group, so I can continue scrolling the main menu.) by pressing a 4th button.
What have you tried so far?
My button is working, and my group navigation is otherwise fine.
At this stage I manually add the buttons to the groups. Then when the time comes, I remove all objects from the sub menu group, and unfreeze the main menu group, I also reregister the input devices to the main menu group. But focus stays on the first item in the second group.
Something I noticed:
When I am scrolling through the sub menu group (lets say I have obj 3 focussed, and I click button 4, focus goes back to the first item in the group. It is as if the group gets deleted and remade automatically.
Code snippets
I unfortunately don’t have a simulator running. But I will show the important bits:
The cb for clicking a main menu item:
void Display_Focus_SubMenu(lv_event_t * e)
{
//Freeze the main group
lv_group_focus_freeze(MenuGroup, true);
//Register the input device to the sub menu group
lv_indev_set_group(MyInputDevice, SubmenuGroup);
lv_indev_set_group(MyInputDevice2, SubmenuGroup);
//Add the items to the sub menu group
for(uint8_t i = 0; i < SubMenuItemCount; i++)
{
if(lv_group_get_focused(MenuGroup) == SubMenuItems[i].ParentMenu)
{
//Show these items
lv_group_add_obj(SubmenuGroup, SubMenuItems[i].Object);
lv_obj_add_event_cb(SubMenuItems[i].Object, Display_Focus_MainMenu, LV_EVENT_CANCEL, SubMenuItems[i].ParentMenu);
}
}
}
The callback for clicking “Esc” on a sub menu button
void Display_Focus_MainMenu(lv_event_t * e)
{
//remove all objects from sub menu group
lv_group_remove_all_objs(SubmenuGroup);
//Register the input devices back to the main menu group
lv_indev_set_group(MyInputDevice, MenuGroup);
lv_indev_set_group(MyInputDevice2, MenuGroup);
//Unfreeze the main menu group
lv_group_focus_freeze(MenuGroup, false);
//Focus the parent item in the main menu
lv_group_focus_obj(e->user_data);
}
Screenshot and/or video
I can try and show my layout as follows: