added update for menu
This commit is contained in:
+27
-20
@@ -11,14 +11,14 @@
|
||||
#include "menu.h"
|
||||
|
||||
Menu::Menu() {
|
||||
this->it = this->entrys.begin();
|
||||
this->selectedEntry = this->entrys.begin();
|
||||
}
|
||||
|
||||
void Menu::addEntry(MenuAction* entry) {
|
||||
this->entrys.push_back(entry);
|
||||
|
||||
if (this->entrys.size() == 2)
|
||||
this->it = this->entrys.begin();
|
||||
this->selectedEntry = this->entrys.begin();
|
||||
}
|
||||
|
||||
void Menu::printMenu() {
|
||||
@@ -26,9 +26,9 @@ void Menu::printMenu() {
|
||||
lcd->clear();
|
||||
lcd->setCursor(0, 0);
|
||||
lcd->print("-> ");
|
||||
lcd->print((**this->it).getName());
|
||||
lcd->print((**this->selectedEntry).getName());
|
||||
lcd->setCursor(0, 1);
|
||||
std::list<MenuAction*>::iterator iter = this->it;
|
||||
std::list<MenuAction*>::iterator iter = this->selectedEntry;
|
||||
iter++;
|
||||
if (iter != this->entrys.end()) {
|
||||
lcd->print((**iter).getName());
|
||||
@@ -37,7 +37,7 @@ void Menu::printMenu() {
|
||||
} else {
|
||||
std::cout << std::endl;
|
||||
for (std::list<MenuAction*>::iterator iter = this->entrys.begin(); iter != this->entrys.end(); iter++) {
|
||||
if (this->it == iter)
|
||||
if (this->selectedEntry == iter)
|
||||
std::cout << " " << (**iter).getName() << std::endl;
|
||||
else
|
||||
std::cout << (**iter).getName() << std::endl;
|
||||
@@ -46,54 +46,61 @@ void Menu::printMenu() {
|
||||
this->inSubmenu = false;
|
||||
}
|
||||
|
||||
void Menu::update() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->selectedEntry).getMenu()->update();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Menu::down() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->down();
|
||||
(**this->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;
|
||||
std::list<MenuAction*>::iterator iter = this->selectedEntry;
|
||||
iter++;
|
||||
if (iter != this->entrys.end())
|
||||
this->it++;
|
||||
this->selectedEntry++;
|
||||
else
|
||||
this->it = this->entrys.begin();
|
||||
this->selectedEntry = this->entrys.begin();
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void Menu::up() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->up();
|
||||
(**this->selectedEntry).getMenu()->up();
|
||||
return;
|
||||
}
|
||||
std::list<MenuAction*>::iterator iter = this->entrys.end();
|
||||
iter--;
|
||||
if (this->it != this->entrys.begin()) {
|
||||
this->it--;
|
||||
if (this->selectedEntry != this->entrys.begin()) {
|
||||
this->selectedEntry--;
|
||||
}
|
||||
else {
|
||||
this->it = iter;
|
||||
this->selectedEntry = iter;
|
||||
}
|
||||
this->printMenu();
|
||||
}
|
||||
|
||||
void Menu::right() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->right();
|
||||
(**this->selectedEntry).getMenu()->right();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((**this->it).getIsMenu()) {
|
||||
if ((**this->selectedEntry).getIsMenu()) {
|
||||
this->inSubmenu = true;
|
||||
(**this->it).getMenu()->setParentMenu(this);
|
||||
(**this->selectedEntry).getMenu()->setParentMenu(this);
|
||||
}
|
||||
(**this->it).runAction();
|
||||
(**this->selectedEntry).runAction();
|
||||
}
|
||||
|
||||
void Menu::left() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->left();
|
||||
(**this->selectedEntry).getMenu()->left();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -103,7 +110,7 @@ void Menu::left() {
|
||||
|
||||
void Menu::yes() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->yes();
|
||||
(**this->selectedEntry).getMenu()->yes();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -112,7 +119,7 @@ void Menu::yes() {
|
||||
|
||||
void Menu::no() {
|
||||
if (this->inSubmenu) {
|
||||
(**this->it).getMenu()->no();
|
||||
(**this->selectedEntry).getMenu()->no();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user