120 lines
2.7 KiB
C++
120 lines
2.7 KiB
C++
/**
|
|
* @file menu.cpp
|
|
* @author Alexander Klein (alex@kleiax.de)
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2022-01-12
|
|
*
|
|
* @copyright Copyright (c) 2022
|
|
*
|
|
*/
|
|
#include "menu.h"
|
|
|
|
Menu::Menu() {
|
|
this->it = this->entrys.begin();
|
|
}
|
|
|
|
void Menu::addEntry(MenuAction* entry) {
|
|
this->entrys.push_back(entry);
|
|
|
|
// TODO: Same shit here. Why I get the first element after an increment.
|
|
static uint8_t inc = 0;
|
|
inc++;
|
|
if (inc == 2) {
|
|
this->it = this->entrys.begin();
|
|
}
|
|
}
|
|
|
|
void Menu::printMenu() {
|
|
Serial.println("\n\n");
|
|
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
|
MenuAction* selectedEntry = *(iter);
|
|
if (this->it == iter)
|
|
Serial.print(" ");
|
|
Serial.println(selectedEntry->getName());
|
|
}
|
|
this->inSubmenu = false;
|
|
}
|
|
|
|
void Menu::down() {
|
|
if (this->inSubmenu) {
|
|
MenuAction* selectedEntry = *(this->it);
|
|
selectedEntry->getMenu()->down();
|
|
return;
|
|
}
|
|
|
|
// TODO: Why I need the fucking next two lines? here and in the next function
|
|
std::list<MenuAction*>::iterator iter = this->it;
|
|
iter++;
|
|
if (iter != this->entrys.end())
|
|
this->it++;
|
|
else
|
|
this->it = this->entrys.begin();
|
|
this->printMenu();
|
|
}
|
|
|
|
void Menu::up() {
|
|
if (this->inSubmenu) {
|
|
MenuAction* selectedEntry = *(this->it);
|
|
selectedEntry->getMenu()->up();
|
|
return;
|
|
}
|
|
std::list<MenuAction*>::iterator iter = this->entrys.end();
|
|
iter--;
|
|
if (this->it != this->entrys.begin()) {
|
|
Serial.println("--");
|
|
this->it--;
|
|
}
|
|
else {
|
|
Serial.println("begin");
|
|
this->it = iter;
|
|
}
|
|
this->printMenu();
|
|
}
|
|
|
|
void Menu::right() {
|
|
// TODO: find out why i cannot call runAction() directly from the iterator
|
|
MenuAction* selectedEntry = *(this->it);
|
|
|
|
if (this->inSubmenu) {
|
|
selectedEntry->getMenu()->right();
|
|
return;
|
|
}
|
|
|
|
if (selectedEntry->getIsMenu()) {
|
|
this->inSubmenu = true;
|
|
selectedEntry->getMenu()->setParentMenu(this);
|
|
}
|
|
selectedEntry->runAction();
|
|
}
|
|
|
|
void Menu::left() {
|
|
if (this->inSubmenu) {
|
|
MenuAction* selectedEntry = *(this->it);
|
|
selectedEntry->getMenu()->left();
|
|
return;
|
|
}
|
|
|
|
if (parentMenu)
|
|
this->parentMenu->printMenu();
|
|
}
|
|
|
|
void Menu::yes() {
|
|
if (this->inSubmenu) {
|
|
MenuAction* selectedEntry = *(this->it);
|
|
selectedEntry->getMenu()->yes();
|
|
return;
|
|
}
|
|
|
|
this->right();
|
|
}
|
|
|
|
void Menu::no() {
|
|
if (this->inSubmenu) {
|
|
MenuAction* selectedEntry = *(this->it);
|
|
selectedEntry->getMenu()->no();
|
|
return;
|
|
}
|
|
|
|
this->left();
|
|
} |