From b805761415fa09de8ce03e33df153d0a8771d8d0 Mon Sep 17 00:00:00 2001 From: Reed Nightingale Date: Sun, 9 Feb 2020 14:10:08 -0800 Subject: [PATCH] Start building a menu 'class' --- menu.cpp | 30 ++++++++++++++++++++++++++++++ menu.h | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 menu.cpp create mode 100644 menu.h diff --git a/menu.cpp b/menu.cpp new file mode 100644 index 0000000..7ea45cb --- /dev/null +++ b/menu.cpp @@ -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; +} \ No newline at end of file diff --git a/menu.h b/menu.h new file mode 100644 index 0000000..1cca722 --- /dev/null +++ b/menu.h @@ -0,0 +1,34 @@ +#pragma once + +#include +#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); \ No newline at end of file