FastLED 3.9.15
Loading...
Searching...
No Matches
ui.cpp
Go to the documentation of this file.
1#include "fl/ui.h"
2#include "fl/stdint.h"
4
7
8namespace fl {
9
10void UISlider::setValue(float value) {
11 float oldValue = mImpl.value();
12 if (value != oldValue) {
14 // Update the last frame value to keep state consistent
17 // Invoke callbacks to notify listeners (including JavaScript components)
18 mCallbacks.invoke(*this);
19 }
20}
21
23 UISlider &owner = *mOwner;
24 if (!owner.mLastFramevalueValid) {
25 owner.mLastFrameValue = owner.value();
26 owner.mLastFramevalueValid = true;
27 return;
28 }
29 float value = owner.value();
30 if (value != owner.mLastFrameValue) {
31 owner.mCallbacks.invoke(*mOwner);
32 owner.mLastFrameValue = value;
33 }
34}
35
37 bool clicked_this_frame = mOwner->clicked();
38
39 // Check the real button if one is attached
40 if (mOwner->mRealButton) {
41 if (mOwner->mRealButton->isPressed()) {
42 clicked_this_frame = true;
43 //mOwner->click(); // Update the UI button state
44 }
45 }
46
47 const bool clicked_changed = (clicked_this_frame != mClickedLastFrame);
48 mClickedLastFrame = clicked_this_frame;
49 if (clicked_changed) {
50 // FASTLED_WARN("Button: " << mOwner->name() << " clicked: " <<
51 // mOwner->clicked());
52 mOwner->mCallbacks.invoke(*mOwner);
53 }
54 // mOwner->mCallbacks.invoke(*mOwner);
55}
56
58 UICheckbox &owner = *mOwner;
59 if (!owner.mLastFrameValueValid) {
60 owner.mLastFrameValue = owner.value();
61 owner.mLastFrameValueValid = true;
62 return;
63 }
64 bool value = owner.value();
65 if (value != owner.mLastFrameValue) {
66 owner.mCallbacks.invoke(owner);
67 owner.mLastFrameValue = value;
68 }
69}
70
72 UINumberField &owner = *mOwner;
73 if (!owner.mLastFrameValueValid) {
74 owner.mLastFrameValue = owner.value();
75 owner.mLastFrameValueValid = true;
76 return;
77 }
78 double value = owner.value();
79 if (value != owner.mLastFrameValue) {
80 owner.mCallbacks.invoke(owner);
81 owner.mLastFrameValue = value;
82 }
83}
84
86 UIDropdown &owner = *mOwner;
87
88 // Check the next button if one is attached
89 bool shouldAdvance = false;
90 if (owner.mNextButton) {
91 if (owner.mNextButton->clicked()) {
92 shouldAdvance = true;
93 }
94 }
95
96 // If the next button was clicked, advance to the next option
97 if (shouldAdvance) {
98 owner.nextOption();
99 // The option change will be detected below and callbacks will be invoked
100 }
101
102 if (!owner.mLastFrameValueValid) {
103 owner.mLastFrameValue = owner.as_int();
104 owner.mLastFrameValueValid = true;
105 return;
106 }
107 int value = owner.as_int();
108 if (value != owner.mLastFrameValue) {
109 owner.mCallbacks.invoke(owner);
110 owner.mLastFrameValue = value;
111 }
112}
113
114} // end namespace fl
115
bool mLastFramevalueValid
Definition ui.h:125
float value
Definition ui.h:47
UISliderImpl mImpl
Definition ui.h:97
float mLastFrameValue
Definition ui.h:124
FunctionList< UISlider & > mCallbacks
Definition ui.h:123
float value() const
Definition ui_impl.h:69
void setValue(float value)
Definition ui_impl.h:72
#define FL_DISABLE_WARNING(warning)
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
IMPORTANT!
Definition crgb.h:20
void onBeginFrame() override
void onBeginFrame() override
void onBeginFrame() override
void onBeginFrame() override
void onBeginFrame() override
UISlider * mOwner
Definition ui.h:118