mirror of
https://codeberg.org/mclemens/ubitxv6.git
synced 2025-07-05 17:27:48 -04:00
Start building a menu 'class'
This commit is contained in:
parent
e35a9eecec
commit
b805761415
30
menu.cpp
Normal file
30
menu.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "menu.h"
|
||||||
|
|
||||||
|
bool runSubmenu(Menu_t* current_menu,
|
||||||
|
void(*redraw_callback)(),
|
||||||
|
ButtonPress_e tuner_button,
|
||||||
|
ButtonPress_e touch_button,
|
||||||
|
Point touch_point,
|
||||||
|
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;
|
||||||
|
}
|
34
menu.h
Normal file
34
menu.h
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "nano_gui.h"//Point
|
||||||
|
|
||||||
|
enum MenuReturn_e : uint8_t {
|
||||||
|
StillActive,
|
||||||
|
ExitedRedraw,
|
||||||
|
ExitedNoRedraw
|
||||||
|
};
|
||||||
|
|
||||||
|
enum ButtonPress_e : uint8_t {
|
||||||
|
NotPressed,
|
||||||
|
ShortPress,
|
||||||
|
LongPress
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Menu_t {
|
||||||
|
MenuReturn_e (*runMenu)(ButtonPress_e tuner_button,
|
||||||
|
ButtonPress_e touch_button,
|
||||||
|
Point touch_point,
|
||||||
|
int16_t knob);
|
||||||
|
Menu_t* active_submenu;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const uint8_t MENU_KNOB_COUNTS_PER_ITEM = 10;
|
||||||
|
|
||||||
|
//Returns true if submenu was run, false otherwise
|
||||||
|
bool runSubmenu(Menu_t* current_menu,
|
||||||
|
void(*redraw_callback)(),
|
||||||
|
ButtonPress_e tuner_button,
|
||||||
|
ButtonPress_e touch_button,
|
||||||
|
Point touch_point,
|
||||||
|
int16_t knob);
|
Loading…
x
Reference in New Issue
Block a user