Skip to content

Commit

Permalink
Popups refactor (#449)
Browse files Browse the repository at this point in the history
* Popups refactor
* Add title to USB modes popup
* cleanup
  • Loading branch information
ajjjjjjjj authored Dec 19, 2024
1 parent bb3c68b commit 3a633ce
Show file tree
Hide file tree
Showing 28 changed files with 168 additions and 81 deletions.
4 changes: 0 additions & 4 deletions radio/src/gui/128x64/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ void editSingleName(coord_t x, coord_t y, const char * label, char * name, uint8
uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay);
#define EDIT_DELAY(x, y, event, attr, str, delay) editDelay(y, event, attr, str, delay)

#define WARNING_TYPE_ASTERISK 0
#define WARNING_TYPE_CONFIRM 1
#define WARNING_TYPE_INPUT 2

extern const char * warningText;
extern const char * warningInfoText;
extern uint8_t warningInfoLength;
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/128x64/model_custom_scripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void onModelCustomScriptMenu(const char *result)
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
}
}
else {
// The user choosed a lua file in the list
else if (result) {
// The user chosen a lua file in the list
copySelection(sd.file, result, sizeof(sd.file));
memset(sd.inputs, 0, sizeof(sd.inputs));
storageDirty(EE_MODEL);
Expand Down
4 changes: 2 additions & 2 deletions radio/src/gui/128x64/model_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void onTelemetryScriptFileSelectionMenu(const char * result)
POPUP_WARNING(STR_NO_SCRIPTS_ON_SD);
}
}
else {
// The user choosed a file in the list
else if (result != STR_EXIT) {
// The user chosen a file in the list
memcpy(g_model.frsky.screens[screenIndex].script.file, result, sizeof(g_model.frsky.screens[screenIndex].script.file));
storageDirty(EE_MODEL);
LUA_LOAD_MODEL_SCRIPTS();
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/model_logical_switches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ void onLogicalSwitchesMenu(const char *result)
pushMenu(menuModelLogicalSwitchOne);
}
#if defined(SDCARD)
if (result == STR_COPY) {
else if (result == STR_COPY) {

clipboard.type = CLIPBOARD_TYPE_CUSTOM_SWITCH;
clipboard.data.csw = *cs;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/model_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void onModelSelectMenu(const char * result)
SET_WARNING_INFO(modelHeaders[sub].name, sizeof(g_model.header.name), ZCHAR);
}
#if defined(SDCARD)
else {
else if (result != STR_EXIT) {
// The user choosed a file on SD to restore
storageCheck(true);
POPUP_WARNING(eeRestoreModel(sub, (char *)result));
Expand Down
6 changes: 3 additions & 3 deletions radio/src/gui/128x64/model_special_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ void onCustomFunctionsFileSelectionMenu(const char * result)
POPUP_WARNING(func==FUNC_PLAY_SCRIPT ? STR_NO_SCRIPTS_ON_SD : STR_NO_SOUNDS_ON_SD);
}
}
else {
// The user choosed a file in the list
else if (result != STR_EXIT) {
// The user chosen a file in the list
memcpy(cfn->play.name, result, sizeof(cfn->play.name));
storageDirty(eeFlags);
}
Expand Down Expand Up @@ -95,7 +95,7 @@ void onAdjustGvarSourceLongEnterPress(const char * result)
CFN_PARAM(cfn) = 0;
storageDirty(EE_MODEL);
}
else {
else if (result != STR_EXIT) {
onSourceLongEnterPress(result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/128x64/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void runPopupWarning(event_t event)
warningResult = false;
drawMessageBox();
if (warningInfoText) {
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, WARNING_INFO_FLAGS);
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, warningInfoFlags);
}
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+4*FH+2, warningType == WARNING_TYPE_ASTERISK ? STR_EXIT : STR_POPUPS_ENTER_EXIT);
switch (event) {
Expand Down
143 changes: 110 additions & 33 deletions radio/src/gui/128x64/popups.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#ifndef _POPUPS_H_
#define _POPUPS_H_

#include <inttypes.h>
#include "buzzer.h"

extern const char * warningText;
extern const char * warningInfoText;
extern uint8_t warningInfoLength;
extern uint8_t warningResult;
extern uint8_t warningType;
extern uint8_t warningInfoFlags;

#define MESSAGEBOX_X 8
#define MESSAGEBOX_Y 8
#define MESSAGEBOX_W (LCD_W - 15)
Expand All @@ -33,58 +43,125 @@
#define WARNING_LINE_X 12
#define WARNING_LINE_Y MESSAGEBOX_Y + 2

#define POPUP_MENU_MAX_LINES 12
#define MENU_MAX_DISPLAY_LINES 6
#define MENU_LINE_LENGTH (LEN_MODEL_NAME+12)

enum {
MENU_OFFSET_INTERNAL,
MENU_OFFSET_EXTERNAL
};

typedef void (* PopupFunc)(event_t event);
extern PopupFunc popupFunc;
extern uint8_t popupMenuOffsetType;

extern uint16_t popupMenuOffset;
extern const char * popupMenuItems[POPUP_MENU_MAX_LINES];
extern uint16_t popupMenuItemsCount;
typedef void (* PopupMenuHandler)(const char * result);
extern PopupMenuHandler popupMenuHandler;
extern const char * popupMenuTitle;
extern uint8_t popupMenuSelectedItem;

// Message box
void drawMessageBoxBackground(coord_t top, coord_t height);
void drawMessageBox();
void showMessageBox(const char * title);
void runPopupWarning(event_t event);

#define DRAW_MESSAGE_BOX(title) (warningText = title, drawMessageBox(), warningText = NULL)
// Popup menu
const char * runPopupMenu(event_t event);
void runPopupWarning(event_t event);

extern void (*popupFunc)(event_t event);
extern uint8_t warningInfoFlags;
enum
{
WARNING_TYPE_WAIT,
WARNING_TYPE_INFO,
WARNING_TYPE_ASTERISK,
WARNING_TYPE_CONFIRM,
WARNING_TYPE_INPUT
};

#if !defined(GUI)
#define DISPLAY_WARNING(...)
#define POPUP_WARNING(...)
#define POPUP_CONFIRMATION(...)
#define POPUP_INPUT(...)
#define WARNING_INFO_FLAGS 0
#define SET_WARNING_INFO(...)
#else
#define DISPLAY_WARNING (*popupFunc)
#define POPUP_WARNING(s) (warningText = s, warningInfoText = 0, popupFunc = runPopupWarning)
#define POPUP_CONFIRMATION(s) (warningText = s, warningType = WARNING_TYPE_CONFIRM, warningInfoText = 0, popupFunc = runPopupWarning)
#define POPUP_INPUT(s, func) (warningText = s, popupFunc = func)
#define WARNING_INFO_FLAGS warningInfoFlags
#define SET_WARNING_INFO(info, len, flags) (warningInfoText = info, warningInfoLength = len, warningInfoFlags = flags)
#define DISPLAY_WARNING(evt) (*popupFunc)(evt)
// #define POPUP_CONFIRMATION(s) (warningText = s, warningType = WARNING_TYPE_CONFIRM, warningInfoText = 0, popupFunc = runPopupWarning)
// #define POPUP_INPUT(s, func) (warningText = s, popupFunc = func)
#endif


inline void POPUP_WARNING(const char * s)
{
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_ASTERISK;
popupFunc = runPopupWarning;
}

inline void POPUP_CONFIRMATION(const char * s/*, PopupMenuHandler handler*/)
{
if (s != warningText) {
// killAllEvents();
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_CONFIRM;
popupFunc = runPopupWarning;
// popupMenuHandler = handler;
}
}

inline void POPUP_INPUT(const char * s, PopupFunc func)
{
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_INPUT;
popupFunc = func;
}

inline void SET_WARNING_INFO(const char * info, uint8_t length, uint8_t flags)
{
warningInfoText = info;
warningInfoLength = length;
warningInfoFlags = flags;
}

inline void POPUP_MENU_ADD_ITEM(const char * s)
{
popupMenuOffsetType = MENU_OFFSET_INTERNAL;
if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) {
popupMenuItems[popupMenuItemsCount++] = s;
}
}

#if defined(SDCARD)
#define POPUP_MENU_ADD_SD_ITEM(s) POPUP_MENU_ADD_ITEM(s)
#else
#define POPUP_MENU_ADD_SD_ITEM(s)
#endif

#define NAVIGATION_MENUS
#define POPUP_MENU_ADD_ITEM(s) do { popupMenuOffsetType = MENU_OFFSET_INTERNAL; if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) popupMenuItems[popupMenuItemsCount++] = s; } while (0)
#define POPUP_MENU_SELECT_ITEM(s) s_menu_item = (s > 0 ? (s < popupMenuItemsCount ? s : popupMenuItemsCount) : 0)
#define POPUP_MENU_START(func) do { popupMenuHandler = (func); AUDIO_KEY_PRESS(); } while (0)
#define POPUP_MENU_MAX_LINES 12
#define MENU_MAX_DISPLAY_LINES 6
#define MENU_LINE_LENGTH (LEN_MODEL_NAME+12)

enum {
MENU_OFFSET_INTERNAL,
MENU_OFFSET_EXTERNAL
};
extern uint8_t popupMenuOffsetType;
extern uint8_t s_menu_item;

#if defined(NAVIGATION_MENUS)
extern uint16_t popupMenuOffset;
extern const char * popupMenuItems[POPUP_MENU_MAX_LINES];
extern uint16_t popupMenuItemsCount;
const char * runPopupMenu(event_t event);
extern void (*popupMenuHandler)(const char * result);
#endif
inline void POPUP_MENU_SELECT_ITEM(uint8_t index)
{
popupMenuSelectedItem = (index > 0 ? (index < popupMenuItemsCount ? index : popupMenuItemsCount) : 0);
}

inline void POPUP_MENU_TITLE(const char * s)
{
popupMenuTitle = s;
}

inline void POPUP_MENU_START(PopupMenuHandler handler)
{
if (handler != popupMenuHandler) {
// killAllEvents(); // not ported yet
AUDIO_KEY_PRESS();
popupMenuHandler = handler;
}
}


#endif // _POPUPS_H_
4 changes: 0 additions & 4 deletions radio/src/gui/212x64/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ void editSingleName(coord_t x, coord_t y, const char * label, char * name, uint8
uint8_t editDelay(coord_t y, event_t event, uint8_t attr, const char * str, uint8_t delay);
#define EDIT_DELAY(y, event, attr, str, delay) editDelay(y, event, attr, str, delay)

#define WARNING_TYPE_ASTERISK 0
#define WARNING_TYPE_CONFIRM 1
#define WARNING_TYPE_INPUT 2

void copySelection(char * dst, const char * src, uint8_t size);

extern const char * warningText;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/212x64/popups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void runPopupWarning(event_t event)
drawMessageBox(warningText);

if (warningInfoText) {
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, WARNING_INFO_FLAGS);
lcdDrawSizedText(WARNING_LINE_X, WARNING_LINE_Y+FH, warningInfoText, warningInfoLength, warningInfoFlags);
}

lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+2*FH, warningType == WARNING_TYPE_ASTERISK ? STR_EXIT : STR_POPUPS_ENTER_EXIT);
Expand Down
6 changes: 2 additions & 4 deletions radio/src/gui/212x64/popups.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
void drawMessageBox(const char * title);
void showMessageBox(const char * title);
void runPopupWarning(event_t event);
#define DRAW_MESSAGE_BOX(title) drawMessageBox(title)

extern void (*popupFunc)(event_t event);
extern uint8_t warningInfoFlags;
Expand All @@ -40,11 +39,10 @@ extern uint8_t warningInfoFlags;
#define POPUP_WARNING(s) (warningText = s, warningInfoText = 0, popupFunc = runPopupWarning)
#define POPUP_CONFIRMATION(s) (warningText = s, warningType = WARNING_TYPE_CONFIRM, warningInfoText = 0, popupFunc = runPopupWarning)
#define POPUP_INPUT(s, func) (warningText = s, popupFunc = func)
#define WARNING_INFO_FLAGS warningInfoFlags
#define SET_WARNING_INFO(info, len, flags) (warningInfoText = info, warningInfoLength = len, warningInfoFlags = flags)

#define POPUP_MENU_ADD_ITEM(s) do { popupMenuOffsetType = MENU_OFFSET_INTERNAL; if (popupMenuItemsCount < POPUP_MENU_MAX_LINES) popupMenuItems[popupMenuItemsCount++] = s; } while (0)
#define POPUP_MENU_SELECT_ITEM(s) s_menu_item = (s > 0 ? (s < popupMenuItemsCount ? s : popupMenuItemsCount) : 0)
#define POPUP_MENU_SELECT_ITEM(s) popupMenuSelectedItem = (s > 0 ? (s < popupMenuItemsCount ? s : popupMenuItemsCount) : 0)
#define POPUP_MENU_START(func) do { popupMenuHandler = (func); AUDIO_KEY_PRESS(); } while (0)
#define POPUP_MENU_MAX_LINES 12
#define MENU_MAX_DISPLAY_LINES 6
Expand All @@ -59,7 +57,7 @@ enum {
MENU_OFFSET_EXTERNAL
};
extern uint8_t popupMenuOffsetType;
extern uint8_t s_menu_item;
extern uint8_t popupMenuSelectedItem;
const char * runPopupMenu(event_t event);
extern void (*popupMenuHandler)(const char * result);

Expand Down
Loading

0 comments on commit 3a633ce

Please sign in to comment.