FastLED 3.9.15
Loading...
Searching...
No Matches
button.cpp.hpp
Go to the documentation of this file.
1#include "fl/ui/button.h"
3#include "fl/stl/noexcept.h"
4
5namespace fl {
6
7UIButton::UIButton(const char *name) FL_NOEXCEPT : mImpl(name), mListener(this) {
8 mListener.addToEngineEventsOnce();
9}
10
12
14 return mImpl.clickedCount() + mListener.realButtonClickCount();
15}
16
18 bool clicked_this_frame = mOwner->clicked();
19 bool pressed_this_frame = mOwner->isPressed();
20
21 // Check the real button if one is attached (via IButtonInput interface)
22 if (mOwner->mButtonInput) {
23 // Edge-detect rising transitions of mButtonInput->clicked() so
24 // clickedCount() reflects real-button presses on platforms where
25 // UIButtonImpl::clickedCount() is a no-op stub.
26 const bool real_clicked = mOwner->mButtonInput->clicked();
27 if (real_clicked && !mRealButtonClickedLastFrame) {
29 }
30 mRealButtonClickedLastFrame = real_clicked;
31
32 if (mOwner->mButtonInput->isPressed()) {
33 clicked_this_frame = true;
34 pressed_this_frame = true;
35 }
36 }
37
38 // Detect press event (was not pressed, now is pressed)
39 if (pressed_this_frame && !mPressedLastFrame) {
40 mOwner->mPressCallbacks.invoke();
41 }
42
43 // Detect release event (was pressed, now is not pressed)
44 if (!pressed_this_frame && mPressedLastFrame) {
45 mOwner->mReleaseCallbacks.invoke();
46 }
47
48 mPressedLastFrame = pressed_this_frame;
49
50 const bool clicked_changed = (clicked_this_frame != mClickedLastFrame);
51 mClickedLastFrame = clicked_this_frame;
52 if (clicked_changed) {
53 mOwner->mCallbacks.invoke(*mOwner);
54 }
55}
56
57} // namespace fl
~UIButton() FL_NOEXCEPT
int clickedCount() const FL_NOEXCEPT
Listener mListener
Definition button.h:160
UIButtonImpl mImpl
Definition button.h:124
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
UIButton * mOwner
Definition button.h:145
bool mRealButtonClickedLastFrame
Definition button.h:149
void onBeginFrame() FL_NOEXCEPT override