Switching between groups


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?


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

	//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

Screenshot and/or video

I can try and show my layout as follows:

I think I found something.

I noticed that the “Display_Focus_SubMenu” was being called immediately after pressing btn 4.

I found that the focus was indeed moving to the main menu, but immediately back to the sub-menu. So the “Pressed” event was being processed by the main menu object after the “Cancel” event was being handled by the sub-menu.

It seems weird that the input device events are carried over even after reregistering the input device, but this might be useful in some cases I guess.

Anyway, I ended up changing the EV_PRESSED to EV_CLICKED, now this happens slower, although the input device event is still being processed twice (Once by the submenu group obj (as a “CANCEL”, which then causes the switch to the main menu group, where the “CLICKED” is processed a second time, moving focus back to the sub menu group.

Is there a way to make sure input device is cleared when moving it to a new group? Or how can I filter which input device triggered an event? Because the “CLICKED” event in the main menu group only needs to be triggered by the encoder button, so I could possibly fix this if I can filter the event by input device?

Ok I got it. Simple mistake, but let me share it anyway.

Originally, when I was setting up my inputs, I was playing around with the encoder buttons.

It seems that btn 4 was still part of the first input device, so I had 1 button trigger two PRESSED states.

Thanks for reading, hope this helps someone.