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:
Rob French 2020-06-10 23:58:15 -05:00
parent 66d1924685
commit 2ea9c96e47

View File

@ -13,8 +13,8 @@
extern SpeechCompressor speechCompressor; // This should be somewhere else. extern SpeechCompressor speechCompressor; // This should be somewhere else.
// 16 characters on display // 16 characters on display
#define MAX_TEXT_LEN 16 const int MAX_TEXT_LEN = 16;
#define MENU_SELECTED_CHAR '>' const char MENU_SELECTED_CHAR = '>';
const char blankLine[17] = " "; const char blankLine[17] = " ";
@ -29,25 +29,89 @@ class MenuItem {
virtual MenuItem* prev() = 0; virtual MenuItem* prev() = 0;
virtual MenuItem* next() = 0; virtual MenuItem* next() = 0;
}; };
/*
//======================================================================
// ListMenu
//======================================================================
const int MAX_LISTMENU_TEXT_LEN = 15;
class ListMenu : public MenuItem { class ListMenu : public MenuItem {
public: public:
ListMenu(const char* title, std::initializer_list<MenuItem*> items) { ListMenu(const char* text, std::initializer_list<const MenuItem*> items):
_items = new MenuItem*[items.size()]; _length(items.size()), _current(0), _dirty(true)
} {
virtual ~MenuItem() { char temp[MAX_LISTMENU_TEXT_LEN];
delete _items; strncpy(temp, text, MAX_LISTMENU_TEXT_LEN);
} temp[MAX_LISTMENU_TEXT_LEN] = '\0';
virtual void update() {
//sprintf(_text, " _items = new MenuItem*[_length];
int count = 0;
for (auto element : items) {
_items[count] = element;
count++;
}
sprintf(_text, "%c%s", MENU_SELECTED_CHAR, temp);
} }
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: private:
bool _dirty;
MenuItem** _items; 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 modeID[] = {'s', 'S', 'c', 'C', 'd', 'D', 't', 'T'};
const char* const filterID[NUM_RIG_MODES][NUM_RX_FILTERS] = { const char* const filterID[NUM_RIG_MODES][NUM_RX_FILTERS] = {
{"2.8", "2.4", "1.8"}, // LSB {"2.8", "2.4", "1.8"}, // LSB