Draw fullscreen single color obj without focus


So, I want to have a button that while pressed will just fill the full screen with a single color rectangle. Once the button is released I want it to return to the previous screen.

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


What LVGL version are you using?


What do you want to achieve?

While the button pressed, a fullscreen rectangle pops-up. The button released returns to the previous screen.

What have you tried so far?

Option 1) Create a full-size canvas
Problem: It works but requires a considerable size buffer to be allocated.

Option 2) Create a container with an opaque background.
Problem: As soon as the container is displayed, the focus shifts to the container and the RELEASE event is not captured.

Option 3) Create a generic obj with an opaque background.
Problem: Same as two.

Callback code

            if(nullptr == m_fullCont)
                /*m_canvas = lv_canvas_create(lv_scr_act(), NULL);
                lv_canvas_set_buffer(m_canvas, m_cbuf, LCD_WIDTH, LCD_HEIGHT, LV_IMG_CF_TRUE_COLOR);
                lv_obj_align(m_canvas, NULL, LV_ALIGN_CENTER, 0, 0);
                lv_canvas_fill_bg(m_canvas, LV_COLOR_GREEN, LV_OPA_COVER);*/
                m_fullCont = lv_obj_create(lv_scr_act(), NULL);
                lv_obj_set_style_local_bg_opa(m_fullCont, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_COVER);
                lv_obj_set_style_local_bg_color(m_fullCont, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN );
                lv_obj_set_size(m_fullCont, LCD_WIDTH, LCD_HEIGHT);
                //Overlay active. Do nothing
            m_fullCont = nullptr;

I’m not sure if any of the options is the best one, but I feel that option 3 if I can fix the focus it should work!

Any suggestions?

So… I was able to add a callback to this new m_fullCont obj and when this new object gets released it deletes itself. I guess this works, but it would be great if I could avoid this extra callback!

You can try using the event protection feature. I believe LV_PROTECT_PRESS_LOST should keep the input events being sent to the button.

1 Like

That worked like a charm!

Thanks @embeddedt