Encoder: How to make object not "focused"

Description

I’m using an encoder and my goal is to have an object, in this case, a switch as a child, but when moving my encoder I want to “focus” the parent, skip the child object, and go to the next.

I’m not sure if this is relevant, but the parent button is also a child of a grid layout

What LVGL version are you using?

v8.3

What do you want to achieve?

Have some objects as not “focusable” by the encoder

What have you tried so far?

    lv_obj_clear_flag(switch, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_clear_flag(switch, LV_OBJ_FLAG_CLICK_FOCUSABLE);
    lv_obj_clear_flag(switch, LV_OBJ_FLAG_CHECKABLE);

@kisvegabor

I was able to reduce this to just screen creation and adding a switch/buttons to the screen, and as you can see, turning the knob (thus inputting NEXT) can highlight the button that is set to not be clickable.

Do you have any suggestions?

{
    mp_screen = lv_obj_create(nullptr);

    lv_obj_t *ptemp = lv_btn_create(GetScreen());
    lv_obj_set_align(ptemp, LV_ALIGN_LEFT_MID);

    ptemp = lv_btn_create(GetScreen());
    lv_obj_set_align(ptemp, LV_ALIGN_CENTER);
    lv_obj_clear_flag(ptemp, LV_OBJ_FLAG_CLICKABLE);
    lv_obj_clear_flag(ptemp, LV_OBJ_FLAG_CHECKABLE);
    lv_obj_clear_flag(ptemp, LV_OBJ_FLAG_CLICK_FOCUSABLE);

    ptemp = lv_btn_create(GetScreen());
    lv_obj_set_align(ptemp, LV_ALIGN_RIGHT_MID);
}

btn

I simply add to group only objects …

  g1 = lv_group_create();
  lv_indev_set_group(encoder_indev, g1);

  ui_init();

  lv_group_add_obj(g1, ui_objtocontrol1);
...

I thought about it, and it does work, however, it doesn’t seem like the correct solution to the problem. At this point, I would like to understand if this is expected behavior or not.

The encoder focuses the widget only from the group which is assigned to the input device. And widgets are automatically added the default group if it’s set.

I suggest searching for lv_group_set_default() to find where it is set and created.

It took me a minute to understand that part but I understood the group idea, and I’m currently setting a group for each independent screen, to simplify things, while that screen is in focus, the focused screen group is the default group. So all objects created while the screen is up, belong to the ‘current default group’.

I think my question is a bit different. I would like to know if is possible to create an object, and set it to as not ‘selectable’ by the encoder;

The result would be similar to having an Object that belongs to a group that does not receive any input or doesn’t belong to a group at all.

However, it seems to me that I should be able to archive this without having to resort to a special group or group less object workaround; clearing the LV_OBJ_FLAG_CLICK_FOCUSABLE should, IMO, make this object unfocusable by the encode (in the same way a label isn’t).

Do you think this is a valid expectation or is there an implication that I’m not seeing?

If a widget is in the group, it will be focusable by the encoder. Unfortunately there is no FLAG or other feature to overwrite it.

However you can do 2 things:

  1. Do not set a default group and manually add the required widgets to the group by using lv_group_add_obj(group, obj)
  2. Keep using the default group, but remove the widgets if needed by lv_group_remove_obj(obj)
1 Like

I went with option 2) as this is the exception not the rule for most screens.

Thanks for the help @kisvegabor and @Marian_M