Avoid pressing button after as swipe onto it


How to not click on a button after swiping on it and releasing finger from it?

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

nRF52832 Arduino c++

What do you want to achieve?

Right now a button will be clicked / short clicked when a finger is pressed anywhere on the touchscreen / input device and swiped onto the button and released from there.

I only want the button to be pressed when the finger was also placed on it at press

What have you tried so far?

Using short clicked instead of clicked

Code to reproduce

      btn1 = lv_btn_create(lv_scr_act(), NULL);
      lv_obj_set_event_cb(btn1, lv_event_handler);
      lv_obj_align(btn1, NULL, LV_ALIGN_IN_BOTTOM_MID, -55, 0);
      lv_btn_set_fit2(btn1, LV_FIT_NONE, LV_FIT_TIGHT);
      btn1_label = lv_label_create(btn1, NULL);
      lv_label_set_text(btn1_label, "Abort");

    virtual void lv_event_handler(lv_obj_t * object, lv_event_t event)
      if (object == btn1 && event == LV_EVENT_SHORT_CLICKED) {
   /* this will get executed*/

Screenshot and/or video


You can use LV_PROTECT_PRESS_LOST on the background. It tells LVGL to not search for a new object after pressing the object. Be sure the background object (screen?) is clickable.

lv_obj_set_click(bg, true);
lv_obj_add_protect(bg, LV_PROTECT_PRESS_LOST);
1 Like