SOLVED LV_EVENT_PRESS_LOST event not functional

Description

I am not receiving the LV_EVENT_PRESS_LOST event on a button or image button. When I press down on the button and drag off of the button and then release, the button is still clicked.

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

I have tested this on the simulator. Ubuntu Linux 22.04.

What LVGL version are you using?

8.3

What do you want to achieve?

I want to know when the user drags their finger off of a button to avoid it being pressed. Ideally if the LV_EVENT_PRESS_LOST is ever triggered it should indicate an attempt to stop whatever action was going to take place.

What have you tried so far?

Check the code below.

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

Copy this code and call the test() function

static void event(lv_event_t * event)
{
    static uint8_t processEvent = 1;

    if(event->code == LV_EVENT_CLICKED)
    {
        if(processEvent)
            printf("Button Clicked\n");
        processEvent = 1;
    }
    else if(event->code == LV_EVENT_PRESS_LOST)
    {
        processEvent = 0;
        printf("LOST!!!\n");
    }
}

void test()
{
    lv_obj_t * btn = lv_btn_create(lv_scr_act());                  /*Add a button the current screen*/
    lv_obj_set_pos(btn, 10, 80);                                    /*Set its position*/
    lv_obj_set_size(btn, 120, 50);                                  /*Set its size*/
    lv_obj_add_event_cb(btn, event, LV_EVENT_ALL, NULL);     /*Assign a callback to the button*/

    lv_obj_t * label = lv_label_create(btn);                        /*Add a label to the button*/
    lv_label_set_text(label, "New Button");                         /*Set the labels text*/
    lv_obj_center(label);
}

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

It could be that your button has this flag activated:

You could clear that flag like
lv_obj_clear_flag(btn, LV_OBJ_FLAG_PRESS_LOCK);

1 Like

This did the trick, thank you

1 Like