| 57 | : mButton(pin, strategy), mListener(this), mPressedLastFrame(false), mClickedThisFrame(false) {} |
| 58 | |
| 59 | void Button::Listener::onEndFrame() { |
| 60 | const bool pressed_curr_frame = mOwner->mButton.isPressed(); |
| 61 | const bool pressed_last_frame = mOwner->mPressedLastFrame; |
| 62 | // Rising edge of isPressed() == one click event for this frame. |
| 63 | // mClickedThisFrame must reflect only the current frame's transition; |
| 64 | // callers (UIDropdown::Listener, UIButton::clickedCount edge counter) |
| 65 | // rely on clicked() being transient, not latched. |
| 66 | const bool clicked_this_frame = pressed_curr_frame && !pressed_last_frame; |
| 67 | mOwner->mPressedLastFrame = pressed_curr_frame; |
| 68 | mOwner->mClickedThisFrame = clicked_this_frame; |
| 69 | if (clicked_this_frame) { |
| 70 | mOwner->mOnClickCallbacks.invoke(); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | Button::Listener::Listener(Button *owner) : mOwner(owner) { |
| 75 | addToEngineEventsOnce(); |