Button receives "pressed" event when another (pressed) object is withdrawn

Hello,

I have a menu-popup which hides some buttons. This menu-popup contains buttons which close this popup when they receive an LV_EVENT_PRESSED.

When the popup disappears, the finger is still on the touchscreen, so the underlying button (which is no longer hidden) immediately receives an LV_EVENT_PRESSED.

This feels very strange, because the user never intended to press the (hidden) button. All the user wanted to do was to choose some menu-entry from the popup, which in turn removes this popup and unhides the (hidden) button.

I recommend using LV_EVENT_CLICKED for buttons. It fires on release, and thus this problem won’t occur.

I see.

Are there any suggestions on when to use which type of events? I just moved from “clicked” to “pressed” because of this issue

You can use the input event list as a reference for which one gets fired when, but it depends mainly on the behavior you want for your application.

If you want to be notified the instant the button gets touched, you have to use PRESSED.

If you just want to be notified when it gets clicked, CLICKED will be more reliable in certain edge cases like the one you found.

Now, I’m getting something weird…LV_EVENT_CLICKED is firing when my finger is still pressing down on the button.

Environment: Sparkfun ESP32 THING, using LVGL 8.01.

Button creation code.

lv_obj_t *button = lv_btn_create(_screen);
lv_obj_add_event_cb(button, buttonHandler_thunk, LV_EVENT_CLICKED, &_buttonPressedClickArgs);
lv_obj_align(button, LV_ALIGN_TOP_LEFT,_nextButtonLeft, _nextButtonTop);  
screen->applySubButtonStyle(button);
  
lv_obj_set_user_data(button,&_buttonMaps[exercise]);
lv_obj_t *label = lv_label_create(button);

lv_label_set_text(label, exerciseNames[exercise].c_str());
lv_obj_set_width(button, _buttonWidth);    
lv_obj_set_height(button, _buttonHeight);
lv_obj_center(label);

_nextButtonLeft += _buttonXStep;
if (_nextButtonLeft + _buttonWidth > _buttonMaxRight)
{
    _nextButtonLeft = _firstButtonLeft;
    _nextButtonTop += _buttonYStep;      
}

Anyone else getting this?

Hmm… is there a possibility that your touchscreen driver doesn’t implement debouncing? You could add some printf statements in read_cb to see if the state is changing there.

Good thought. I’ll have a look. If it is that, I’ll just add something to reject a second press within x ms.