Rotary encoder weird behaviour


I am using a rotary encoder as an input for switching between screens, but once I leave the main screen, it is possible to select objects that are outside of that particular screen.

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

Arduino ESP32S3

What do you want to achieve?

Only being able to focus/select objects that are visible on that screen.

What have you tried so far?

I’m tried wrestling with focus and groups but I can’t get it to work properly.

In-depth description

I made the UI with squareline studio and ported it to arduino.
I used the following code for creating a group for being able to focus objects:

 void init_lv_group() {
   lv_group = lv_group_create();

   lv_indev_t *cur_drv = NULL;
   for (;;) {
     cur_drv = lv_indev_get_next(cur_drv);
     if (!cur_drv) {

     if (cur_drv->driver->type == LV_INDEV_TYPE_ENCODER) {
       lv_indev_set_group(cur_drv, lv_group);

This code is called before the ui_init(); function generated by squareline.

I have a main screen with 2 buttons to select a submenu/subscreen, I can only select the object that are visible on that screen. (So it works fine).

Once I move to a submenu I’m able to select objects that are outside of that particular screen (So objects from other screens). So the selection goes all funny.

I tried to add the objects of that screen to a group and removed the objects outside of the screen from the group but I can’t seem to get it working. (I did this in the button released event function).

I also tried using focus turn on and turn off but that also doesn’t affect it.

Any tips on how to solve it? I tried searching for examples with multiple screens and a rotary encoder, but the results are very limited unfortunately. All examples are welcome!

Little bug?

At first I tried to return to the main menu when the button is pressed/released (without turning the rotary encoder first, purely a clicked event on the screen), but when I do this I get a weird rendering bug in which a lot of copies of the screen are rendered on top of each other. It looks very similar as to if you have a long mouse trail enabled on your pc. And at the end of the rendering it stays at the same screen. Is this maybe a rendering bug or are you simply not allowed to do this?