Have a high level function in charge of finding the active submenu

This commit is contained in:
Reed Nightingale 2020-02-15 14:43:05 -08:00
parent 2bfa97687d
commit 98adba28ba
6 changed files with 38 additions and 52 deletions

32
menu.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "menu.h"
#include "menu_main.h"
void runActiveMenu(const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob)
{
Menu_t* parent_menu = rootMenu;//rootMenu is it's own parent
Menu_t* active_menu = rootMenu;
while(nullptr != active_menu->active_submenu){
parent_menu = active_menu;
active_menu = parent_menu->active_submenu;
}
MenuReturn_e mr = active_menu->runMenu(tuner_button,touch_button,touch_point,knob);
switch(mr){
case MenuReturn_e::StillActive://Fallthrough intended
case MenuReturn_e::ExitedNoRedraw:
{
//Nothing to do here - just return
break;
}
default://Fallthrough intended. Default to this menu being active
case MenuReturn_e::ExitedRedraw:
{
//Turn off submenu, redraw, then return
parent_menu->active_submenu = nullptr;
parent_menu->initMenu();
break;
}
}//end switch
}

5
menu.h
View File

@ -25,3 +25,8 @@ struct Menu_t {
};
static const uint8_t MENU_KNOB_COUNTS_PER_ITEM = 10;
void runActiveMenu(const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob);

View File

@ -85,20 +85,6 @@ MenuReturn_e runMainMenu(const ButtonPress_e tuner_button,
const Point touch_point,
const int16_t knob)
{
if(runSubmenu(&mainMenu,
drawMainMenu,
tuner_button,
touch_button,
touch_point,
knob)){
//Submenu processed the input, so return now
mainMenuSelectedItemRaw = 0;
mainMenuSelecting = false;
return MenuReturn_e::StillActive;//main menu always returns StillActive
}//end submenu
//Submenu didn't run, so handle the inputs ourselves
//Check tuner_button
if(ButtonPress_e::NotPressed != tuner_button){
switch(tuner_button){

View File

@ -8,35 +8,6 @@
#include "nano_gui.h"
#include "utils.h"
bool runSubmenu(Menu_t *const current_menu,
void(*const redraw_callback)(),
const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob){
if(nullptr != current_menu->active_submenu){
auto ret = current_menu->active_submenu->runMenu(tuner_button,touch_button,touch_point,knob);
switch(ret){
case MenuReturn_e::StillActive://Fallthrough intended
case MenuReturn_e::ExitedNoRedraw:
{
//Nothing to do here - just return
break;
}
default://Fallthrough intended. Default to this menu being active
case MenuReturn_e::ExitedRedraw:
{
//Turn off submenu, redraw, then return
current_menu->active_submenu = nullptr;
redraw_callback();
break;
}
}//end switch
return true;
}//end submenu
return false;
}
bool findPressedButton(const Button* const* buttons,
const uint8_t num_buttons,
Button *const button_out,

View File

@ -3,14 +3,6 @@
#include "button.h"
#include "menu.h"
//Returns true if submenu was run, false otherwise
bool runSubmenu(Menu_t* current_menu,
void(*const redraw_callback)(),
const ButtonPress_e tuner_button,
const ButtonPress_e touch_button,
const Point touch_point,
const int16_t knob);
//Returns true if button was found, false otherwise
bool findPressedButton(const Button* const* buttons,
const uint8_t num_buttons,

View File

@ -506,5 +506,5 @@ void loop(){
Point touch_point;
ButtonPress_e touch_button = checkTouch(&touch_point);
int16_t knob = enc_read();
rootMenu->runMenu(tuner_button,touch_button,touch_point,knob);
runActiveMenu(tuner_button,touch_button,touch_point,knob);
}