Bind
C++ UI toolkit for Arduino
 
Loading...
Searching...
No Matches
BindButton.hpp
1#ifndef __BINDBUTTON_H
2#define __BINDBUTTON_H
3#include "BindView.hpp"
4#include "BindUtils.hpp"
5
25class BindButton : public BindView
26{
27
28public:
37 BindButton(const char *cstr)
38 {
39 setlabel(cstr);
40 }
41
43 {
44 setlabel("Button");
45 }
46
47 int16_t x;
48 int16_t y;
49 uint8_t cmdId = 0;
50 int16_t fontSize;
51 int32_t textColor;
52 int32_t backColor;
53
62 void setlabel(const char *cstr)
63 {
64 str = cstr;
65 }
66
76 uint16_t getBytes(uint8_t *out) override
77 {
78 offset = 0;
79 strLength = strlen(str);
80 if (strLength > MAX_STRING_LENGTH_TERMINAL)
81 {
82 strLength = MAX_STRING_LENGTH_TERMINAL;
83 }
84 copyAndOffset(out, &offset, &objID, sizeof(objID));
85 copyAndOffset(out, &offset, &x, sizeof(x));
86 copyAndOffset(out, &offset, &y, sizeof(y));
87 copyAndOffset(out, &offset, &tag, sizeof(tag));
88 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
89 copyAndOffset(out, &offset, &fontSize, sizeof(fontSize));
90 copyAndOffset(out, &offset, &textColor, sizeof(textColor));
91 copyAndOffset(out, &offset, &backColor, sizeof(backColor));
92 copyAndOffset(out, &offset, str, strLength);
93 return offset;
94 }
95
96private:
97 uint8_t objID = BIND_ID_BUTTON;
98 uint16_t offset = 0;
99 int strLength = 0;
100 const char *str;
101};
102#endif /* __BINDBUTTON_H */
The BindButton class represents a button UI element for use with BindCanvas.
Definition BindButton.hpp:26
int16_t x
X-coordinate position of the button.
Definition BindButton.hpp:47
int32_t backColor
Background color of the button.
Definition BindButton.hpp:52
int16_t fontSize
Font size of the button's label.
Definition BindButton.hpp:50
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the button for synchronization.
Definition BindButton.hpp:76
int16_t y
Y-coordinate position of the button.
Definition BindButton.hpp:48
uint8_t cmdId
Command ID for the button. See the notes for possible cmdId values.
Definition BindButton.hpp:49
BindButton(const char *cstr)
Constructs a BindButton with a custom label.
Definition BindButton.hpp:37
int32_t textColor
Text color of the button.
Definition BindButton.hpp:51
void setlabel(const char *cstr)
Sets the label text for the button.
Definition BindButton.hpp:62
Definition BindView.hpp:22