Loading...
Searching...
No Matches
BindButton.hpp
1#ifndef __BINDBUTTON_H
2#define __BINDBUTTON_H
3#include "BindView.hpp"
4#include "BindUtils.hpp"
5
26 class BindButton : public BindView
27{
28
29 public:
38 BindButton(const char *cstr)
39 {
40 setLabel(cstr);
41 this->tag = tagIndex++;
42 }
43
44 BindButton()
45 {
46 setLabel("Button");
47 this->tag = tagIndex++;
48 }
49
50 int16_t x;
51 int16_t y;
52 uint8_t cmdId = 0;
53 int16_t fontSize = 16;
54 int32_t textColor = WHITE;
55 int32_t backColor = BLUE;
56
57 [[deprecated("Use setLabel instead")]]
58 void setlabel(const char *cstr)
59 {
60 setLabel(cstr);
61 }
62
72 void setLabel(const char *cstr)
73 {
74 str = cstr;
75 }
76
77
89 void setCallback(void (*callback)(void))
90 {
91 clickCallback = callback;
92 }
93
94 void invokeCallback()
95 {
96 if (clickCallback != nullptr)
97 {
98 clickCallback();
99 }
100 }
101
111 uint16_t getBytes(uint8_t *out) override
112 {
113 offset = 0;
114 strLength = strlen(str);
115 if (strLength > MAX_STRING_LENGTH_TERMINAL)
116 {
117 strLength = MAX_STRING_LENGTH_TERMINAL;
118 }
119 copyAndOffset(out, &offset, &objID, sizeof(objID));
120 copyAndOffset(out, &offset, &x, sizeof(x));
121 copyAndOffset(out, &offset, &y, sizeof(y));
122 copyAndOffset(out, &offset, &tag, sizeof(tag));
123 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
124 copyAndOffset(out, &offset, &fontSize, sizeof(fontSize));
125 copyAndOffset(out, &offset, &textColor, sizeof(textColor));
126 copyAndOffset(out, &offset, &backColor, sizeof(backColor));
127 copyAndOffset(out, &offset, str, strLength);
128 return offset;
129 }
130
131 private:
132 uint8_t objID = BIND_ID_BUTTON;
133 uint16_t offset = 0;
134 int strLength = 0;
135 const char *str;
136 static int16_t tagIndex;
137 void (*clickCallback)(void) = nullptr;
138};
139#endif /* __BINDBUTTON_H */
BindButton
The BindButton class represents a button UI element for use with BindCanvas.
Definition BindButton.hpp:27
BindButton::x
int16_t x
X-coordinate position of the button.
Definition BindButton.hpp:50
BindButton::backColor
int32_t backColor
Background color of the button.
Definition BindButton.hpp:55
BindButton::fontSize
int16_t fontSize
Font size of the button's label.
Definition BindButton.hpp:53
BindButton::getBytes
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the button for synchronization.
Definition BindButton.hpp:111
BindButton::y
int16_t y
Y-coordinate position of the button.
Definition BindButton.hpp:51
BindButton::cmdId
uint8_t cmdId
Command ID for the button. See the notes for possible cmdId values.
Definition BindButton.hpp:52
BindButton::BindButton
BindButton(const char *cstr)
Constructs a BindButton with a custom label.
Definition BindButton.hpp:38
BindButton::textColor
int32_t textColor
Text color of the button.
Definition BindButton.hpp:54
BindButton::setLabel
void setLabel(const char *cstr)
Sets the callback function for the button.
Definition BindButton.hpp:72
BindButton::setCallback
void setCallback(void(*callback)(void))
Set the press callback function for the button.
Definition BindButton.hpp:89
BindView
Definition BindView.hpp:26