1#ifndef __BINDDIALOG_HPP
2#define __BINDDIALOG_HPP
4#include "BindUtils.hpp"
5#define DIALOG_TEXT_BUFFER_SIZE 64
7#include <avr/pgmspace.h>
8const char DEFAULT_TITLE[] PROGMEM =
"Confirmation";
9const char DEFAULT_MESSAGE[] PROGMEM =
"Are you sure?";
10const char DEFAULT_OK[] PROGMEM =
"OK";
11const char DEFAULT_CANCEL[] PROGMEM =
"Cancel";
13const char DEFAULT_TITLE[] =
"Confirmation";
14const char DEFAULT_MESSAGE[] =
"Are you sure?";
15const char DEFAULT_OK[] =
"OK";
16const char DEFAULT_CANCEL[] =
"Cancel";
54 : dialogType(type), title(
nullptr), message(
nullptr), primaryButton(
"OK"), secondaryButton(
"Cancel")
56 this->tag = tagIndex++;
59 strcpy_P(buffer, DEFAULT_TITLE);
61 strcpy_P(buffer, DEFAULT_MESSAGE);
63 strcpy_P(buffer, DEFAULT_OK);
65 strcpy_P(buffer, DEFAULT_CANCEL);
102 primaryButton = cstr;
112 secondaryButton = cstr;
131 this->callback.simple = callback;
132 isTextCallback =
false;
153 this->callback.withText = callback;
154 isTextCallback =
true;
157 void invokeCallback(
bool result,
const char *text)
162 if ((dialogType == TEXT_INPUT || dialogType == PASSWORD_INPUT) && isTextCallback){
163 setTextResult(text, strlen(text));
164 if (callback.withText !=
nullptr)
166 callback.withText(result, text);
170 if (callback.simple !=
nullptr)
172 callback.simple(result);
178 void invokeCallback(
bool result)
182 if (dialogType == NO_INPUT_TEXT && callback.simple !=
nullptr){
183 callback.simple(result);
196 return resultTextBuffer;
202 uint8_t dialogTypeU = (uint8_t)dialogType;
203 copyAndOffset(out, &offset, &objID,
sizeof(objID));
204 copyAndOffset(out, &offset, &tag,
sizeof(tag));
205 copyAndOffset(out, &offset, &
cmdId,
sizeof(
cmdId));
206 copyAndOffset(out, &offset, &dialogTypeU,
sizeof(dialogTypeU));
209 copyStringWithLength(out, &offset, title);
210 copyStringWithLength(out, &offset, message);
211 copyStringWithLength(out, &offset, primaryButton);
212 copyStringWithLength(out, &offset, secondaryButton);
223 char resultTextBuffer[DIALOG_TEXT_BUFFER_SIZE];
224 uint8_t objID = BIND_ID_DIALOG;
229 const char *primaryButton =
"OK";
230 const char *secondaryButton =
"Cancel";
231 DialogType dialogType;
232 static int16_t tagIndex;
234 void (*simple)(bool);
235 void (*withText)(bool,
const char *);
237 DialogCallback callback;
238 bool isTextCallback =
false;
240 void setTextResult(
const char *cstr,
int length) {
241 length = min(length, DIALOG_TEXT_BUFFER_SIZE - 1);
242 strncpy(resultTextBuffer, cstr, length);
243 resultTextBuffer[length] =
'\0';
BindDialog class represents a dialog box for use with BindCanvas app.
Definition BindDialog.hpp:50
bool singleButton
Flag to indicate if the dialog has a single button.
Definition BindDialog.hpp:220
void setMessage(const char *cstr)
Set the message text for the dialog.
Definition BindDialog.hpp:90
void setCallback(void(*callback)(bool, const char *))
Set the callback function for the dialog with text input.
Definition BindDialog.hpp:151
void setTitle(const char *cstr)
Set the title text for the dialog.
Definition BindDialog.hpp:80
const char * getResultText() const
Get the result text entered by the user.
Definition BindDialog.hpp:195
uint16_t getBytes(uint8_t *out) override
Retrieves the bytes representing the BindView for synchronization.
Definition BindDialog.hpp:199
bool accepted
Result of the user interaction with the dialog.
Definition BindDialog.hpp:218
void setSecondaryButton(const char *cstr)
Set the secondary button text (e.g. "Cancel") for the dialog.
Definition BindDialog.hpp:110
void setPrimaryButton(const char *cstr)
Set the primary button text (e.g. "OK") for the dialog.
Definition BindDialog.hpp:100
uint8_t cmdId
Command ID for the dialog. See the notes for possible cmdId values.
Definition BindDialog.hpp:217
bool hasResult
Flag to indicate if the dialog has a result. The resets to false after each sync.
Definition BindDialog.hpp:219
void setCallback(void(*callback)(bool))
Set the callback function for the dialog.
Definition BindDialog.hpp:129
Definition BindView.hpp:26