Design Philosophy
Dialog boxes are a simple, generic way to show a message and/or prompt the user for a response.
Example
Const strings and declarations for the example dialog box:
static const char dialogTitle = "Confirmation";
static const char dialogDetail = "Something happened! Continue?";
static const char optCancel[] = "Cancel";
static const char optOk[] = "OK";
static void dialogBoxCb(const char* label);
Initialize the dialog box:
bool dialogComplete = false;
bool confirmed = false;
loadFont(
"ibm_vga8.font", &dialogFont,
false);
loadWsg(
"info.wsg", &infoIcon,
false);
dialogBox_t * initDialogBox(const char *title, const char *detail, const wsg_t *icon, dialogBoxCbFn_t cbFn)
Allocate and return a new dialogBox_t with the given settings.
Definition dialogBox.c:127
Definition dialogBox.h:139
A font is a collection of font_ch_t for all ASCII characters. Each character has the same height and ...
Definition font.h:66
bool loadFont(const char *name, font_t *font, bool spiRam)
Load a font from ROM to RAM. Fonts are bitmapped image files that have a single height,...
Definition fs_font.c:32
bool loadWsg(const char *name, wsg_t *wsg, bool spiRam)
Load a WSG from ROM to RAM. WSGs placed in the assets_image folder before compilation will be automat...
Definition fs_wsg.c:34
A sprite using paletteColor_t colors that can be drawn to the display.
Definition wsg.h:57
Inside the main loop:
if (!dialogComplete)
{
{
}
}
else
{
const char* message = confirmed ? "Confirmed" : "Cancelled";
}
void dialogBoxButton(dialogBox_t *dialogBox, const buttonEvt_t *evt)
Handle button presses for the dialog box.
Definition dialogBox.c:537
#define DIALOG_CENTER
If passed for X or Y, will center the dialog box on that axis.
Definition dialogBox.h:91
#define DIALOG_AUTO
If passed for W or H, will calculate the size of the dialog box based on its contents.
Definition dialogBox.h:94
int16_t drawText(const font_t *font, paletteColor_t color, const char *text, int16_t xOff, int16_t yOff)
Draw text to a display with the given color and font.
Definition font.c:214
uint16_t textWidth(const font_t *font, const char *text)
Return the pixel width of some text in a given font.
Definition font.c:226
uint8_t height
The height of this font. All chars have the same height.
Definition font.h:67
void clearPxTft(void)
Clear all pixels in the display to black.
Definition hdw-tft.c:404
@ c555
r = 5, g = 5, b = 5
Definition palette.h:239
bool checkButtonQueueWrapper(buttonEvt_t *evt)
Service the queue of button events that caused interrupts This only returns a single event,...
Definition swadge2024.c:740
static void dialogBoxCb(const char* label)
{
if (optCancel == label)
{
printf("Cancel\n");
dialogComplete = true;
}
else if (optOk == label)
{
printf("OK!\n");
dialogComplete = true;
confirmed = true;
}
}
|
dialogBox_t * | initDialogBox (const char *title, const char *detail, const wsg_t *icon, dialogBoxCbFn_t cbFn) |
| Allocate and return a new dialogBox_t with the given settings.
|
|
void | deinitDialogBox (dialogBox_t *dialogBox) |
| Deallocate all memory associated with the given dialog box.
|
|
void | dialogBoxAddOption (dialogBox_t *dialogBox, const char *label, const wsg_t *icon, dialogOptionHint_t hints) |
| Add an option button to a dialog box.
|
|
void | dialogBoxReset (dialogBox_t *dialogBox) |
| Clear all options from the given dialog box.
|
|
void | drawDialogBox (const dialogBox_t *dialogBox, const font_t *titleFont, const font_t *detailFont, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r) |
| Draw the dialog box.
|
|
void | dialogBoxButton (dialogBox_t *dialogBox, const buttonEvt_t *evt) |
| Handle button presses for the dialog box.
|
|