mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2025-02-21 06:57:27 -05:00
Have a high level function in charge of finding the active submenu
This commit is contained in:
parent
2bfa97687d
commit
98adba28ba
32
menu.cpp
Normal file
32
menu.cpp
Normal 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
5
menu.h
@ -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);
|
||||
|
@ -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){
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user