Focusing the object in the group does not work

Description

Hi
I have three external hardware keys, and I use an input device implemented as an encoder.
I use two screens on one physical display. Each screen has its own group. When the screen is active/inactive, I call the event functions LV_EVENT_SCREEN_LOADED and LV_EVENT_SCREEN_UNLOADED.

Screen has different objects: labels, slider, checkbox…

I can’t focus on a specific object in the group.

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

ESP32-C3, ESP-IDF v5.0

What LVGL version are you using?

v8.3.9

if(groupScreen1 == NULL)
{
     groupScreen1 = lv_group_create();
}
lv_group_remove_all_objs(groupScreen1 );

lv_group_add_obj(groupScreen1 , slider1_Screen1);
lv_group_add_obj(groupScreen1 , obj1_Screen1);
lv_group_add_obj(groupScreen1 , label1_Screen1);
lv_group_add_obj(groupScreen1 , obj2_Screen1);

static lv_group_t * groupScreen1 = NULL;
static lv_obj_t * obj1_Screen1;
static lv_obj_t * obj2_Screen1;
static lv_obj_t * obj3_Screen1;

static void Screen1_EventCb(lv_event_t * e)
{
	lv_event_code_t code = lv_event_get_code(e);

	if (code == LV_EVENT_SCREEN_LOADED)
	{
		lv_indev_wait_release(lv_indev_get_act());

		lv_group_set_defocused(Group_GetDefault());
		Group_SetDefault(groupScreen1);
		lv_group_set_defocused(Group_GetDefault());
		
		lv_group_focus_obj(obj1_Screen1);

	}
}

When the second screen is visible, then in the event function Screen2_EventCb I assign the group in a similar way.

Please, what is the exact order of calling the functions, how to set the group as the default group?

Tnx

Why you mean cant focus ?

If I want to focus object “obj1_Screen1”, i call the function lv_group_focus_obj(obj1_Screen1);, then some other object is focused from the group, eg object obj2_Screen1 from the group

If I want to focus object “obj3_Screen1”, i call the function lv_group_focus_obj(obj3_Screen1);, then some other object is focused from the group, eg object label2_Screen1 from the group

I cannot control the focus of the object.

I mean focus is ok, but you object receive next or prev event and this jump focus to other object. For edit object after focus is required swith to edit mode…

I am using the lv_menu component to create a menu. All screens are created at once, as well as associated objects, object styles, groups…

When opening an individual sub-menu (Screen), the function LV_EVENT_SCREEN_LOADED is called, as well as the LV_EVENT_SCREEN_UNLOADED function when the screen closes.
When the menu is closed, all created objects are destroyed.

Question: Should I delete the group created for each screen, as well as the used style.
Objects are automatically destroyed?

Can you help, what is the family of actions and what actions need to be performed when switching from screen to screen, as well as when closing the menu?

Tnx

@kisvegabor can you help? :slight_smile:
Tnx

Focusing on the desired object does not work.
This is part of subMenu, creating objects on the screen of a submenu.
There are three objects:

  • ExitBtn - to exit the current subMenu
  • switch object
  • label object

Code:

lv_group_t * gMenu = NULL;

static lv_obj_t *labelNum;
static lv_obj_t *swEnable;

static void SubMenu_EventCb(lv_event_t * e)
{
	lv_event_code_t code = lv_event_get_code(e);

	if (code == LV_EVENT_SCREEN_LOADED)
	{
		if(subMenuScreen.screen != UI_SUBSCREEN_ALARM)
		{
			SubMenuLoaded(labelNum);
		}
	}
	else if (code == LV_EVENT_SCREEN_UNLOADED)
	{
		UnloadedScreen();
	}
}

static void SubMenuLoaded(lv_obj_t * obj)
{
	IndevWaitRelease();		// lv_indev_wait_release(lv_indev_get_act());

    if(gMenu == NULL)	
    	gMenu = lv_group_create();

	lv_group_remove_all_objs(gMenu);

	Group_SetDefault(gMenu);			

    //!< Add object
	lv_group_add_obj(Group_GetDefault(), swEnable);
	lv_group_add_obj(Group_GetDefault(), labelNum);
	lv_group_add_obj(Group_GetDefault(), lv_menu_get_main_header_back_btn(ui_MenuScreen));	// BackBtn menu

	//!< Focused object
	if(obj) {
		if(!lv_obj_has_flag(obj, LV_OBJ_FLAG_HIDDEN)) 
		{
			lv_group_focus_obj(obj);
		}
		else 
		{
			lv_group_focus_obj(swEnableDelay);
		}
	}
	else {
		lv_group_focus_obj(swEnableDelay);
	}
}

void Group_SetDefault(lv_group_t* group)
{
	if(group == NULL)
		group = lv_group_create();

	lv_group_set_default(group);

    lv_indev_t *indev = lv_indev_get_next(NULL);

    if (LV_INDEV_TYPE_ENCODER == lv_indev_get_type(indev))
    {
        lv_indev_set_group(indev, group);
        lv_group_focus_freeze(group, false);
    }
}

Any help, where am I going wrong? Thank you in advance