Make an object never lose focus


I want to make two containers alternate focus between themselves.

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

Simulator and ESP32

What LVGL version are you using?


What do you want to achieve?

When one container is pressed/clicked it should be focused until the other one is pressed/clicked, in which case the second container will be focused.
I’ve managed to do this, the issue I’m having is when I press on any other object: the page, buttons, etc.

What have you tried so far?

Some buttons and the containers themselves have an event_handler that forces the LV_STATE_FOCUSED on the selected container.

Should I do this for all the objects in the page?
Is there any way to make the objects inherit this from their parent (screen object in this case?)

LVGL automatically changes focus between object when they are selected (pressed).

However there is a workaround: If you add an object to a group LVGL will keep the focused object in the group if an other object outside of the group is selected.

Which input device (indev) should I use in the lv_indev_set_group function as I’m using a touch screen?

I don’t see any LV_INDEV_TYPE_… for touch controllers. Do I have to declare a new one?

I think (although I never use groups) you can just use the indev returned from lv_indev_drv_register; no need to change anything else.

But shouldn’t there be one already initialized? I’m using a touch controller, I suppose it initializes an input driver by itself, no?

For touch to work at all there has to be an lv_indev_drv_register call somewhere in your code. The return value from that is what you should pass to lv_indev_set_group.

I think I recall seeing your name on the lv_port_esp32 discussions, so if you’re using that project, this is where the touchscreen gets registered.

Yes, I am using the simulator but ultimately the project will run in ESP32.

It is registered in that scope, but I need it in another file and scope. Doesn’t seem like a very viable option. Or should I declare it globally?

I’d just declare it globally.

From my understanding, groups will be registered to an input driver. That input driver will only work for said group. Is this correct?

If so, it wouldn’t solve my issue, since I have objects outside that “group” that need to be interacted with as well.

I think touchscreens will work with any object regardless of its group.