FastLED 3.10.8
Loading...
Searching...
No Matches
checkbox.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/function.h"
4#include "fl/stl/string.h"
5#include "fl/stl/compiler_control.h" // IWYU pragma: keep
6#include "fl/stl/noexcept.h"
8#include "fl/ui/element.h"
9#include "platforms/ui_defs.h"
10
11#ifndef FASTLED_HAS_UI_CHECKBOX
12#define FASTLED_HAS_UI_CHECKBOX 0
13#endif
14
15namespace fl {
16
17#if !FASTLED_HAS_UI_CHECKBOX
18
20 public:
21 UICheckboxImpl(const char *name, bool value = false) : mValue(value) {
22 FASTLED_UNUSED(name);
23 }
25 operator bool() const { return mValue; }
26 explicit operator int() const { return mValue ? 1 : 0; }
29 return *this;
30 }
32 setValue(value != 0);
33 return *this;
34 }
35 bool value() const { return mValue; }
36
37 // Stub method for group setting (does nothing on non-WASM platforms)
38 void setGroup(const fl::string& groupName) { FASTLED_UNUSED(groupName); }
39
40 private:
41 void setValue(bool value) { mValue = value; }
42 bool mValue;
43};
44
45#endif
46
47class UICheckbox : public UIElement {
48 public:
50 UICheckbox(const char *name, bool value = false) FL_NO_EXCEPT;
52
53 operator bool() const FL_NO_EXCEPT { return value(); }
54 explicit operator int() const FL_NO_EXCEPT { return static_cast<int>(value()); }
56 mImpl = value;
57 return *this;
58 }
59 bool value() const FL_NO_EXCEPT { return mImpl.value(); }
60
61 // Override setGroup to also update the implementation
62 void setGroup(const fl::string& groupName) FL_NO_EXCEPT override {
63 UIElement::setGroup(groupName);
64 // Update the implementation's group if it has the method (WASM platforms)
65 mImpl.setGroup(groupName);
66 }
67
68
69 void onChanged(function<void(UICheckbox &)> callback) FL_NO_EXCEPT {
70 mCallbacks.add(callback);
71 mListener.addToEngineEventsOnce();
72 }
74
75 protected:
77
80 // Don't register in constructor - prevents callbacks before owner is fully initialized
81 }
83 if (added) {
85 }
86 }
88 if (added) {
89 return;
90 }
92 added = true;
93 }
94 void onBeginFrame() FL_NO_EXCEPT override;
95
96 private:
98 bool added = false;
99 };
100
101 private:
102 function_list<void(UICheckbox &)> mCallbacks;
103 bool mLastFrameValue = false;
106};
107
109
110} // namespace fl
static void removeListener(Listener *listener) FL_NO_EXCEPT
static void addListener(Listener *listener, int priority=0) FL_NO_EXCEPT
void setGroup(const fl::string &groupName) FL_NO_EXCEPT override
Definition checkbox.h:62
UICheckbox & operator=(bool value) FL_NO_EXCEPT
Definition checkbox.h:55
Listener mListener
Definition checkbox.h:105
void onChanged(function< void(UICheckbox &)> callback) FL_NO_EXCEPT
Definition checkbox.h:69
FL_NO_COPY(UICheckbox)
function_list< void(UICheckbox &)> mCallbacks
Definition checkbox.h:102
bool mLastFrameValue
Definition checkbox.h:103
UICheckbox(const char *name, bool value=false) FL_NO_EXCEPT
void clearCallbacks() FL_NO_EXCEPT
Definition checkbox.h:73
bool value() const FL_NO_EXCEPT
Definition checkbox.h:59
UICheckboxImpl mImpl
Definition checkbox.h:76
bool mLastFrameValueValid
Definition checkbox.h:104
void setValue(bool value)
Definition checkbox.h:41
~UICheckboxImpl() FL_NO_EXCEPT
Definition checkbox.h:24
void setGroup(const fl::string &groupName)
Definition checkbox.h:38
UICheckboxImpl & operator=(int value) FL_NO_EXCEPT
Definition checkbox.h:31
UICheckboxImpl & operator=(bool value) FL_NO_EXCEPT
Definition checkbox.h:27
bool value() const
Definition checkbox.h:35
UICheckboxImpl(const char *name, bool value=false)
Definition checkbox.h:21
virtual void setGroup(const fl::string &groupName) FL_NO_EXCEPT
Definition element.h:31
UIElement() FL_NO_EXCEPT
#define FASTLED_UNUSED(x)
#define FASTLED_UI_DEFINE_OPERATORS(UI_CLASS)
Definition element.h:40
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
Base definition for an LED controller.
Definition crgb.hpp:179
UICheckbox * mOwner
Definition checkbox.h:97
void onBeginFrame() FL_NO_EXCEPT override
Listener(UICheckbox *owner) FL_NO_EXCEPT
Definition checkbox.h:79
void addToEngineEventsOnce() FL_NO_EXCEPT
Definition checkbox.h:87
~Listener() FL_NO_EXCEPT
Definition checkbox.h:82