Iterate through the list to find the focused object

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

For pointer input devices like crown, which cannot focus like touch screens or mouse clicks, I am trying to automatically focus on the menu with multiple lists when entering the page. I am not sure if it is feasible.

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

BES2700BP

What LVGL version are you using?

LVGL 8.3.10

What do you want to achieve?

Assuming there are multiple lists on the display and one of them has focus, I want to query the coordinates of this focus. When calling the lv_indev_search_obj function, pass in the parameters to achieve automatic focusing.

What have you tried so far?

Add a query function _lv_ll_obj_find to find the focused object

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

Pass the coordinates of the focus object to act_point

/*If there is no last object then search*/
if(indev_obj_act == NULL) {
	lv_point_t fouse_point;
	lv_obj_t *fouse_obj = _lv_ll_obj_find();
	if(fouse_obj) {
		fouse_point.x = (fouse_obj->coords.x1 + fouse_obj->coords.x2) / 2;
		fouse_point.y = (fouse_obj->coords.y1 + fouse_obj->coords.y2) / 2;
	}
	else {
		fouse_point = proc->types.pointer.act_point;
	}

	if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_sys(disp), &fouse_point);
	if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_layer_top(disp),
																	  &fouse_point);
	if(indev_obj_act == NULL) indev_obj_act = lv_indev_search_obj(lv_disp_get_scr_act(disp),
																	  &fouse_point);
	new_obj_searched = true;
}

Searching for the focus object is currently causing a crash.

lv_obj_t * _lv_ll_obj_find(void)
{
    lv_ll_t * ll_p  = &LV_GC_ROOT(_lv_group_ll);
    void * i;
    void * i_next;
    lv_obj_t *obj_find = NULL;

    i      = _lv_ll_get_head(ll_p);
    i_next = NULL;

    while(i != NULL) {
        i_next = _lv_ll_get_next(ll_p, i);
        lv_group_t *group = (lv_group_t *)i_next;
        if (*(group->obj_focus)) {
            obj_find = *(group->obj_focus);
            break;
        }

        i = i_next;
    }

    return obj_find;
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

Sorry but I don’t understand what to goal would be. Could you describe what you would like to see (not the possible solution just the goal)

(Maybe gridnav can help)

I don’t know if this is what you want

HI kisvegabor,
I want to know how the knob can auto-focus, unlike the mouse that needs to be clicked.

Sorry, but I still don’t understand. Please describe step by step what you would like to achieve. A screenshot from the UI can be helpful too.

You should just create an lv_group and call lv_group_focus_next/prev(group) on button presses. See here.

Okay, I understand, thanks a lot.