Loading...
Searching...
No Matches
BindTextInput.hpp
1#ifndef __BINDTEXTINPUT_H
2#define __BINDTEXTINPUT_H
3
4#include "BindView.hpp"
5#include "BindUtils.hpp"
6#include "Arduino.h"
15 class BindTextInput : public BindView
16{
17 public:
23 BindTextInput();
41 BindTextInput(int16_t x, int16_t y, uint8_t cmdId, const char *text, const char *hint, int16_t fontSize, int32_t textColor = 0, int32_t backColor = 0, uint8_t widthChars = 0, bool numberOnly = false);
42
54 void setCallback(void (*callback)(const char *, uint8_t))
55 {
56 changeCallback = callback;
57 }
58
59 void invokeCallback(const char *val, uint8_t length)
60 {
61 setText(val, length);
62 if (changeCallback != nullptr)
63 {
64 changeCallback(val, length);
65 }
66 }
67
75 void setText(const char *cstr)
76 {
77 setText(cstr, strlen(cstr));
78 }
79
80 void setText(const char *cstr, int length)
81 {
82 if (cstr == text || length < 0) {
83 return; // Handle self-assignment
84 }
85
86 // Allocate memory for the new text
87 if (text != nullptr) {
88 delete[] text;
89 }
90 text = new char[length + 1];
91 strncpy(text, cstr, length);
92 text[length] = '\0'; // Null-terminate the string
93 strLength = length;
94 }
95
103 void setHint(const char *cstr)
104 {
105 hint = cstr;
106 }
107
108 const char* getText() const
109 {
110 return text;
111 }
112
121 uint16_t getBytes(uint8_t *out) override;
122
123 int16_t x;
124 int16_t y;
125 uint8_t cmdId;
126 int16_t fontSize = 18;
127 int32_t textColor = WHITE;
128 int32_t backColor = TRANSPARENT;
129 uint8_t widthChars;
130 bool numberOnly = false;
131 char *text = nullptr;
132
133
134 private:
135 uint8_t objID = BIND_ID_TEXTINPUT;
136 uint16_t offset = 0;
137 int strLength = 0;
138 const char *hint;
139 static int16_t tagIndex;
140 void (*changeCallback)(const char *, uint8_t) = nullptr;
141};
142
143#endif /* __BINDTEXTINPUT_H */
BindTextInput
The BindTextInput class represents a text input UI element for use with BindCanvas.
Definition BindTextInput.hpp:16
BindTextInput::textColor
int32_t textColor
Text color for the text input.
Definition BindTextInput.hpp:127
BindTextInput::y
int16_t y
Y-coordinate position of the text input.
Definition BindTextInput.hpp:124
BindTextInput::fontSize
int16_t fontSize
Font size for the text input.
Definition BindTextInput.hpp:126
BindTextInput::widthChars
uint8_t widthChars
Width of the text input in characters.
Definition BindTextInput.hpp:129
BindTextInput::backColor
int32_t backColor
Background color for the text input.
Definition BindTextInput.hpp:128
BindTextInput::setCallback
void setCallback(void(*callback)(const char *, uint8_t))
Set the Callback function for the text input.
Definition BindTextInput.hpp:54
BindTextInput::BindTextInput
BindTextInput()
Constructs a BindTextInput with default properties.
Definition BindTextInput.cpp:11
BindTextInput::setHint
void setHint(const char *cstr)
Sets the hint text for the text input.
Definition BindTextInput.hpp:103
BindTextInput::cmdId
uint8_t cmdId
Command ID for the text input.
Definition BindTextInput.hpp:125
BindTextInput::getBytes
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the text input for synchronization.
Definition BindTextInput.cpp:18
BindTextInput::setText
void setText(const char *cstr)
Sets the text content for the text input.
Definition BindTextInput.hpp:75
BindTextInput::x
int16_t x
X-coordinate position of the text input.
Definition BindTextInput.hpp:123
BindTextInput::text
char * text
Text content of the text input.
Definition BindTextInput.hpp:131
BindView
Definition BindView.hpp:26