From 497052d9dfea94c0c157dd15abcffd0622603f2f Mon Sep 17 00:00:00 2001 From: MCMrARM Date: Wed, 16 May 2018 17:34:05 +0200 Subject: [PATCH] Make B exit the app --- source/main.c | 9 ++++++++- source/menu.c | 8 +++++++- source/menu.h | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/source/main.c b/source/main.c index 40896bb..eb85b27 100644 --- a/source/main.c +++ b/source/main.c @@ -7,8 +7,13 @@ FsDeviceOperator fsOperatorInstance; +bool shouldExit = false; bool shouldWaitForAnyButton = false; +void menuExit() { + shouldExit = true; +} + void menuWaitForAnyButton() { printf(C_DIM "Press any button to return to menu\n"); shouldWaitForAnyButton = true; @@ -40,7 +45,7 @@ int main(int argc, char **argv) { return -1; } - menuSetCurrent(mainMenu); + menuSetCurrent(mainMenu, menuExit); while(appletMainLoop()) { @@ -57,6 +62,8 @@ int main(int argc, char **argv) { shouldWaitForAnyButton = false; menuPrint(); } + if (shouldExit) + break; gfxFlushBuffers(); gfxSwapBuffers(); diff --git a/source/menu.c b/source/menu.c index 7e47e9e..f8f9359 100644 --- a/source/menu.c +++ b/source/menu.c @@ -8,6 +8,7 @@ MenuItem* menuCurrent; int menuCurrentCount; bool menuCardIsInserted; int menuSelIndex = 0; +void (*menuExitCallback)(); void menuPrint() { consoleClear(); @@ -43,6 +44,10 @@ int menuHandleInput() { menuCurrent[menuSelIndex].callback(); return -1; } + if ((keys & KEY_B) && menuExitCallback != NULL) { + menuExitCallback(); + return -1; + } if (((keys & KEY_RSTICK_UP) | (keys & KEY_LSTICK_UP)) && menuSelIndex > 0) { menuSelIndex--; needsRefresh = true; @@ -55,7 +60,8 @@ int menuHandleInput() { } -void menuSetCurrent(MenuItem* menuItems) { +void menuSetCurrent(MenuItem* menuItems, void (*exitCallback)()) { + menuExitCallback = exitCallback; menuCurrent = menuItems; menuCurrentCount = 0; while ((menuItems++)->text != NULL) diff --git a/source/menu.h b/source/menu.h index fc425d2..268b09f 100644 --- a/source/menu.h +++ b/source/menu.h @@ -8,5 +8,5 @@ typedef struct { } MenuItem; void menuPrint(); -void menuSetCurrent(MenuItem* menuItems); +void menuSetCurrent(MenuItem* menuItems, void (*exitCallback)()); void menuUpdate(FsDeviceOperator* fsOperator); \ No newline at end of file