From 6464074c128029449d5879c096bedcd9cad4512a Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Fri, 24 Jun 2022 19:28:44 +0100 Subject: [PATCH] jscene: add an option to control main menu manually --- include/justui/jfileselect.h | 2 -- include/justui/jscene.h | 6 ++++++ src/jscene.c | 15 +++++++++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/include/justui/jfileselect.h b/include/justui/jfileselect.h index 1f282b1..9b743cb 100644 --- a/include/justui/jfileselect.h +++ b/include/justui/jfileselect.h @@ -17,8 +17,6 @@ only consists of a scrolling list of names showing a section of a folder's entries. - TODO: jfileselect: Select a new file to write to - Events: * JFILESELECT_LOADED when a folder is loaded into the view * JFILESELECT_VALIDATED when a file has been selected diff --git a/include/justui/jscene.h b/include/justui/jscene.h index 69a804a..95961cb 100644 --- a/include/justui/jscene.h +++ b/include/justui/jscene.h @@ -31,6 +31,8 @@ typedef struct { /* Number of events lots */ uint16_t lost_events; + /* Whether jscene_run() returns to the main menu */ + bool mainmenu; } jscene; @@ -103,6 +105,10 @@ bool jscene_process_key_event(jscene *scene, key_event_t event); Returns true if the event was accepted along the way, false if ignored. */ bool jscene_process_event(jscene *scene, jevent event); +/* jscene_set_mainmenu(): Set whether jscene_run() will return to main menu + Disabling this is useful if you want to catch the MENU key or clean up + resources before invoking the main menu. */ +void jscene_set_mainmenu(jscene *scene, bool mainmenu); /* jscene_run(): Run a scene's main loop diff --git a/src/jscene.c b/src/jscene.c index 4088e24..e7b2ac6 100644 --- a/src/jscene.c +++ b/src/jscene.c @@ -52,6 +52,7 @@ jscene *jscene_create(int x, int y, int w, int h, void *parent) s->queue_first = 0; s->queue_next = 0; s->lost_events = 0; + s->mainmenu = true; /* Prepare first layout/paint operation */ s->widget.dirty = 1; @@ -192,7 +193,11 @@ bool jscene_process_event(GUNUSED jscene *scene, jevent event) return false; } -/* jscene_run(): Run a scene's main loop */ +void jscene_set_mainmenu(jscene *scene, bool mainmenu) +{ + scene->mainmenu = mainmenu; +} + jevent jscene_run(jscene *s) { keydev_t *d = keydev_std(); @@ -214,9 +219,11 @@ jevent jscene_run(jscene *s) key_event_t k = keydev_read(d); if(k.type == KEYEV_DOWN && k.key == KEY_MENU && !k.shift && !k.alpha) { - gint_osmenu(); - jscene_queue_event(s, (jevent){ .type = JSCENE_PAINT }); - continue; + if(s->mainmenu) { + gint_osmenu(); + jscene_queue_event(s, (jevent){ .type = JSCENE_PAINT }); + continue; + } } #ifdef FX9860G if(k.type == KEYEV_DOWN && k.key == KEY_OPTN && k.shift && !k.alpha) {