Popups refactoring

This commit is contained in:
Bertrand Songis
2019-05-03 23:26:17 +02:00
parent 8376e1b16b
commit 7d4adc1afe
8 changed files with 117 additions and 63 deletions
+4 -1
View File
@@ -171,10 +171,13 @@ 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);
}
switch (warningType) {
case WARNING_TYPE_WAIT:
return;
case WARNING_TYPE_INFO:
lcdDrawText(WARNING_LINE_X, WARNING_LINE_Y+2*FH+2, STR_OK);
break;
+109 -2
View File
@@ -21,6 +21,9 @@
#ifndef _STDLCD_POPUPS_H_
#define _STDLCD_POPUPS_H_
#include <inttypes.h>
#include "audio.h"
extern const char * warningText;
extern const char * warningInfoText;
extern uint8_t warningInfoLength;
@@ -28,13 +31,15 @@ extern uint8_t warningResult;
extern uint8_t warningType;
extern uint8_t warningInfoFlags;
extern void (* popupFunc)(event_t event);
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;
extern void (* popupMenuHandler)(const char * result);
typedef void (* PopupMenuHandler)(const char * result);
extern PopupMenuHandler popupMenuHandler;
extern const char * popupMenuTitle;
extern uint8_t s_menu_item;
@@ -53,4 +58,106 @@ void showAlertBox(const char * title, const char * text, const char * action , u
// Full screen with 2 lines and a progress bar
void drawProgressScreen(const char * title, const char * message, int num, int den);
enum
{
WARNING_TYPE_WAIT,
WARNING_TYPE_INFO,
WARNING_TYPE_ASTERISK,
WARNING_TYPE_CONFIRM,
WARNING_TYPE_INPUT
};
#if !defined(GUI)
#define DISPLAY_WARNING(...)
inline void POPUP_WAIT(const char * s) { }
inline void POPUP_WARNING(const char * s) { }
inline void POPUP_CONFIRMATION(const char * s, PopupMenuHandler handler) { }
inline void POPUP_INPUT(const char * s, PopupFunc func) { }
inline void SET_WARNING_INFO(const char * info, uint8_t length, uint8_t flags) { }
#else
#define DISPLAY_WARNING (*popupFunc)
inline void POPUP_WAIT(const char * s)
{
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_WAIT;
popupFunc = runPopupWarning;
}
inline void POPUP_INFORMATION(const char * s)
{
warningText = s;
warningInfoText = nullptr;
warningType = WARNING_TYPE_INFO;
popupFunc = runPopupWarning;
}
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)
{
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 bool isEventCaughtByPopup()
{
if (warningText && warningType != WARNING_TYPE_WAIT)
return true;
if (popupMenuItemsCount > 0)
return true;
return false;
}
#endif
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
inline void POPUP_MENU_SELECT_ITEM(uint8_t index)
{
s_menu_item = (index > 0 ? (index < popupMenuItemsCount ? index : popupMenuItemsCount) : 0);
}
inline void POPUP_MENU_START(PopupMenuHandler handler)
{
popupMenuHandler = handler;
AUDIO_KEY_PRESS();
}
#endif // _STDLCD_POPUPS_H_