Draw fullscreen single color obj without focus

Description

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?

RT1062

What LVGL version are you using?

7.11

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

    switch(e)
    {
        case(LV_EVENT_PRESSING):
        {
            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);
            }
            else
            {
                //Overlay active. Do nothing
            }
            break;
        }
        case(LV_EVENT_RELEASED):
        {
            lv_obj_del(m_fullCont);
            m_fullCont = nullptr;
            break;
        }

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