Bind
C++ UI toolkit for Arduino
 
Loading...
Searching...
No Matches
BindSwitch.hpp
1#ifndef __BINDSWITCH_HPP
2#define __BINDSWITCH_HPP
3#include "BindView.hpp"
4#include "BindUtils.hpp"
31class BindSwitch : public BindView
32{
33public:
39 BindSwitch(const char *cstr)
40 {
41 setlabel(cstr);
42 }
43
48 {
49 setlabel("Switch");
50 }
51
52 int16_t x;
53 int16_t y;
54 uint8_t cmdId = 0;
56 int16_t fontSize;
57 int32_t textColor;
58
64 void setlabel(const char *cstr)
65 {
66 str = cstr;
67 }
68
78 uint16_t getBytes(uint8_t *out) override
79 {
80 offset = 0;
81 strLength = strlen(str);
82 if (strLength > MAX_STRING_LENGTH_TERMINAL)
83 {
84 strLength = MAX_STRING_LENGTH_TERMINAL;
85 }
86 copyAndOffset(out, &offset, &objID, sizeof(objID));
87 copyAndOffset(out, &offset, &x, 2);
88 copyAndOffset(out, &offset, &y, 2);
89 copyAndOffset(out, &offset, &tag, 2);
90 copyAndOffset(out, &offset, &cmdId, sizeof(cmdId));
91 copyAndOffset(out, &offset, &switchValue, sizeof(switchValue));
92 copyAndOffset(out, &offset, &fontSize, sizeof(fontSize));
93 copyAndOffset(out, &offset, &textColor, sizeof(textColor));
94 copyAndOffset(out, &offset, str, strLength);
95 return offset;
96 }
97
98private:
99 uint8_t objID = BIND_ID_TOGGLE_SWITCH;
100 uint16_t offset = 0;
101 int strLength = 0;
102 const char *str;
103};
104
105#endif /* __BINDSWITCH_HPP */
Represents a toggle switch UI element in the Bind framework.
Definition BindSwitch.hpp:32
int16_t y
Y-coordinate position of the toggle switch.
Definition BindSwitch.hpp:53
BindSwitch()
Default constructor to create a BindSwitch with a default label ("Switch").
Definition BindSwitch.hpp:47
uint16_t getBytes(uint8_t *out) override
Generates and returns the byte data representing the toggle switch configuration.
Definition BindSwitch.hpp:78
uint8_t cmdId
Command identifier. See the notes for possible cmdId values.
Definition BindSwitch.hpp:54
bool switchValue
The current state (ON/OFF) of the toggle switch.
Definition BindSwitch.hpp:55
int32_t textColor
Text color for the switch label.
Definition BindSwitch.hpp:57
void setlabel(const char *cstr)
Sets the label text for the toggle switch.
Definition BindSwitch.hpp:64
int16_t fontSize
Font size for the switch label.
Definition BindSwitch.hpp:56
int16_t x
X-coordinate position of the toggle switch.
Definition BindSwitch.hpp:52
BindSwitch(const char *cstr)
Constructor to create a BindSwitch with a custom label.
Definition BindSwitch.hpp:39
Definition BindView.hpp:22