1#ifndef __BINDDIALOG_HPP
2#define __BINDDIALOG_HPP
4#include "BindUtils.hpp"
42 : dialogType(type), title(
nullptr), message(
nullptr), primaryButton(
"OK"), secondaryButton(
"Cancel"), resultText(
nullptr)
44 this->tag = tagIndex++;
54 if (resultText !=
nullptr) {
96 secondaryButton = cstr;
115 this->callback = callback;
136 this->callbackWithText = callback;
139 void invokeCallback(
bool result,
const char *text)
144 if (dialogType == TEXT_INPUT || dialogType == PASSWORD_INPUT){
145 setTextResult(text, strlen(text));
146 if (callbackWithText !=
nullptr)
148 callbackWithText(result, text);
152 if (callback !=
nullptr)
159 void invokeCallback(
bool result)
163 if (callback !=
nullptr)
179 if (resultText !=
nullptr) {
189 uint8_t dialogTypeU = (uint8_t)dialogType;
190 copyAndOffset(out, &offset, &objID,
sizeof(objID));
191 copyAndOffset(out, &offset, &tag,
sizeof(tag));
192 copyAndOffset(out, &offset, &
cmdId,
sizeof(
cmdId));
193 copyAndOffset(out, &offset, &dialogTypeU,
sizeof(dialogTypeU));
196 copyStringWithLength(out, &offset, title);
197 copyStringWithLength(out, &offset, message);
198 copyStringWithLength(out, &offset, primaryButton);
199 copyStringWithLength(out, &offset, secondaryButton);
210 uint8_t objID = BIND_ID_DIALOG;
215 const char *primaryButton =
"OK";
216 const char *secondaryButton =
"Cancel";
217 DialogType dialogType;
218 static int16_t tagIndex;
219 void (*callback)(bool) =
nullptr;
220 void (*callbackWithText)(bool,
const char *) =
nullptr;
221 char *resultText =
nullptr;
223 void setTextResult(
const char *cstr,
int length)
225 if (cstr == resultText || length < 0) {
230 if (resultText !=
nullptr) {
233 resultText =
new char[length + 1];
234 strncpy(resultText, cstr, length);
235 resultText[length] =
'\0';
BindDialog class represents a dialog box for use with BindCanvas app.
Definition BindDialog.hpp:38
bool singleButton
Flag to indicate if the dialog has a single button.
Definition BindDialog.hpp:207
void setMessage(const char *cstr)
Set the message text for the dialog.
Definition BindDialog.hpp:74
void setCallback(void(*callback)(bool, const char *))
Set the callback function for the dialog with text input.
Definition BindDialog.hpp:134
void setTitle(const char *cstr)
Set the title text for the dialog.
Definition BindDialog.hpp:64
const char * getResultText() const
Get the result text entered by the user.
Definition BindDialog.hpp:177
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the BindView for synchronization.
Definition BindDialog.hpp:186
bool accepted
Result of the user interaction with the dialog.
Definition BindDialog.hpp:205
void setSecondaryButton(const char *cstr)
Set the secondary button text (e.g. "Cancel") for the dialog.
Definition BindDialog.hpp:94
void setPrimaryButton(const char *cstr)
Set the primary button text (e.g. "OK") for the dialog.
Definition BindDialog.hpp:84
uint8_t cmdId
Command ID for the dialog. See the notes for possible cmdId values.
Definition BindDialog.hpp:204
bool hasResult
Flag to indicate if the dialog has a result. The resets to false after each sync.
Definition BindDialog.hpp:206
void setCallback(void(*callback)(bool))
Set the callback function for the dialog.
Definition BindDialog.hpp:113
Definition BindView.hpp:22