Created ListMenu class, which uses std::initializer_list to (hopefully)
facilitate creating a large menu. Compiles, but hasn't been tested.
This commit is contained in:
parent
66d1924685
commit
2ea9c96e47
@ -13,8 +13,8 @@
|
||||
extern SpeechCompressor speechCompressor; // This should be somewhere else.
|
||||
|
||||
// 16 characters on display
|
||||
#define MAX_TEXT_LEN 16
|
||||
#define MENU_SELECTED_CHAR '>'
|
||||
const int MAX_TEXT_LEN = 16;
|
||||
const char MENU_SELECTED_CHAR = '>';
|
||||
|
||||
const char blankLine[17] = " ";
|
||||
|
||||
@ -29,25 +29,89 @@ class MenuItem {
|
||||
virtual MenuItem* prev() = 0;
|
||||
virtual MenuItem* next() = 0;
|
||||
};
|
||||
/*
|
||||
|
||||
//======================================================================
|
||||
// ListMenu
|
||||
//======================================================================
|
||||
|
||||
const int MAX_LISTMENU_TEXT_LEN = 15;
|
||||
|
||||
class ListMenu : public MenuItem {
|
||||
public:
|
||||
ListMenu(const char* title, std::initializer_list<MenuItem*> items) {
|
||||
_items = new MenuItem*[items.size()];
|
||||
ListMenu(const char* text, std::initializer_list<const MenuItem*> items):
|
||||
_length(items.size()), _current(0), _dirty(true)
|
||||
{
|
||||
char temp[MAX_LISTMENU_TEXT_LEN];
|
||||
strncpy(temp, text, MAX_LISTMENU_TEXT_LEN);
|
||||
temp[MAX_LISTMENU_TEXT_LEN] = '\0';
|
||||
|
||||
_items = new MenuItem*[_length];
|
||||
|
||||
int count = 0;
|
||||
for (auto element : items) {
|
||||
_items[count] = element;
|
||||
count++;
|
||||
}
|
||||
virtual ~MenuItem() {
|
||||
delete _items;
|
||||
|
||||
sprintf(_text, "%c%s", MENU_SELECTED_CHAR, temp);
|
||||
}
|
||||
virtual void update() {
|
||||
//sprintf(_text, "
|
||||
|
||||
virtual ~ListMenu() {
|
||||
delete [] _items;
|
||||
}
|
||||
|
||||
virtual void update()
|
||||
{
|
||||
if (_dirty) {
|
||||
sendIOPMenuDisplay(_text);
|
||||
_dirty = false;
|
||||
}
|
||||
}
|
||||
|
||||
virtual MenuItem* select()
|
||||
{
|
||||
_dirty = true;
|
||||
return _items[_current];
|
||||
}
|
||||
|
||||
virtual MenuItem* altSelect()
|
||||
{
|
||||
_dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual MenuItem* exit()
|
||||
{
|
||||
_dirty = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virtual MenuItem* prev()
|
||||
{
|
||||
if (--_current < 0) {
|
||||
_current += _length;
|
||||
}
|
||||
_dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
virtual MenuItem* next()
|
||||
{
|
||||
_current = ++_current % _length;
|
||||
_dirty = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
bool _dirty;
|
||||
MenuItem** _items;
|
||||
char _text[MAX_TEXT_LEN+1];
|
||||
int _length;
|
||||
int _current;
|
||||
char _text[MAX_LISTMENU_TEXT_LEN+1];
|
||||
};
|
||||
*/
|
||||
|
||||
//======================================================================
|
||||
|
||||
const char modeID[] = {'s', 'S', 'c', 'C', 'd', 'D', 't', 'T'};
|
||||
const char* const filterID[NUM_RIG_MODES][NUM_RX_FILTERS] = {
|
||||
{"2.8", "2.4", "1.8"}, // LSB
|
||||
|
Loading…
Reference in New Issue
Block a user