1#ifndef __BINDSWITCH_HPP
2#define __BINDSWITCH_HPP
4#include "BindUtils.hpp"
42 this->tag = tagIndex++;
44 this->changeCallback =
nullptr;
52 this->tag = tagIndex++;
55 sprintf(label,
"SW-%d", this->tag);
57 this->changeCallback =
nullptr;
78 void setlabel(
const char *cstr)
96 this->changeCallback = callback;
99 void invokeCallback(
bool val)
102 if (this->changeCallback !=
nullptr)
104 this->changeCallback(val);
120 strLength = strlen(str);
121 if (strLength > MAX_STRING_LENGTH_TERMINAL)
123 strLength = MAX_STRING_LENGTH_TERMINAL;
125 copyAndOffset(out, &offset, &objID,
sizeof(objID));
126 copyAndOffset(out, &offset, &
x, 2);
127 copyAndOffset(out, &offset, &
y, 2);
128 copyAndOffset(out, &offset, &tag, 2);
129 copyAndOffset(out, &offset, &
cmdId,
sizeof(
cmdId));
130 copyAndOffset(out, &offset, &
value,
sizeof(
value));
133 copyAndOffset(out, &offset, str, strLength);
138 uint8_t objID = BIND_ID_TOGGLE_SWITCH;
142 void (*changeCallback)(bool) =
nullptr;
143 static int16_t tagIndex;
Represents a toggle switch UI element in the Bind framework.
Definition BindSwitch.hpp:33
bool value
The current state (ON/OFF) of the toggle switch.
Definition BindSwitch.hpp:63
int16_t y
Y-coordinate position of the toggle switch.
Definition BindSwitch.hpp:61
BindSwitch()
Default constructor to create a BindSwitch with a default label ("Switch").
Definition BindSwitch.hpp:50
uint16_t getBytes(uint8_t *out) override
Generates and returns the byte data representing the toggle switch configuration.
Definition BindSwitch.hpp:117
uint8_t cmdId
Command identifier. See the notes for possible cmdId values.
Definition BindSwitch.hpp:62
void setLabel(const char *cstr)
Sets the label text for the toggle switch.
Definition BindSwitch.hpp:72
void setCallback(void(*callback)(bool))
Set the Callback function for the toggle switch.
Definition BindSwitch.hpp:94
int32_t textColor
Text color for the switch label.
Definition BindSwitch.hpp:65
int16_t fontSize
Font size for the switch label.
Definition BindSwitch.hpp:64
int16_t x
X-coordinate position of the toggle switch.
Definition BindSwitch.hpp:60
BindSwitch(const char *cstr)
Constructor to create a BindSwitch with a custom label.
Definition BindSwitch.hpp:40
Definition BindView.hpp:22