added MenuActionWrapper to call callbacks /classes

This commit is contained in:
2023-01-04 00:14:03 +01:00
parent 4a6e1845f9
commit c723200a27
2 changed files with 31 additions and 3 deletions
+16 -3
View File
@@ -20,19 +20,32 @@ MenuAction::MenuAction(const char* name, MenuControl* menu) {
this->name = name;
this->menu = menu;
this->isMenu = true;
this->callback = nullptr;
}
MenuAction::MenuAction(const char* name, MenuActionWrapper* action) {
this->name = name;
this->action = action;
}
MenuAction::~MenuAction() {
if (this->menu)
delete this->menu;
if (this->action)
delete this->action;
}
void MenuAction::runAction() {
if (isMenu)
this->menu->printMenu();
else
this->function();
else {
if (this->function)
this->function();
else if (this->action)
this->action->action();
else
std::cout << "Error in MenuAction::runAction" << std::endl;
}
if (this->callback)
this->callback();