added MenuActionWrapper to call callbacks /classes
This commit is contained in:
+16
-3
@@ -20,19 +20,32 @@ MenuAction::MenuAction(const char* name, MenuControl* menu) {
|
|||||||
this->name = name;
|
this->name = name;
|
||||||
this->menu = menu;
|
this->menu = menu;
|
||||||
this->isMenu = true;
|
this->isMenu = true;
|
||||||
this->callback = nullptr;
|
}
|
||||||
|
|
||||||
|
MenuAction::MenuAction(const char* name, MenuActionWrapper* action) {
|
||||||
|
this->name = name;
|
||||||
|
this->action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuAction::~MenuAction() {
|
MenuAction::~MenuAction() {
|
||||||
if (this->menu)
|
if (this->menu)
|
||||||
delete this->menu;
|
delete this->menu;
|
||||||
|
|
||||||
|
if (this->action)
|
||||||
|
delete this->action;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuAction::runAction() {
|
void MenuAction::runAction() {
|
||||||
if (isMenu)
|
if (isMenu)
|
||||||
this->menu->printMenu();
|
this->menu->printMenu();
|
||||||
else
|
else {
|
||||||
this->function();
|
if (this->function)
|
||||||
|
this->function();
|
||||||
|
else if (this->action)
|
||||||
|
this->action->action();
|
||||||
|
else
|
||||||
|
std::cout << "Error in MenuAction::runAction" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
if (this->callback)
|
if (this->callback)
|
||||||
this->callback();
|
this->callback();
|
||||||
|
|||||||
@@ -15,6 +15,12 @@
|
|||||||
|
|
||||||
class MenuControl;
|
class MenuControl;
|
||||||
|
|
||||||
|
class MenuActionWrapper {
|
||||||
|
public:
|
||||||
|
virtual ~MenuActionWrapper() {}
|
||||||
|
virtual void action() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This class forms the transition between menus.
|
* @brief This class forms the transition between menus.
|
||||||
*
|
*
|
||||||
@@ -33,6 +39,14 @@ class MenuAction {
|
|||||||
*/
|
*/
|
||||||
MenuAction(const char* name, void (*function) (), void (*callback) () = nullptr);
|
MenuAction(const char* name, void (*function) (), void (*callback) () = nullptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Menu Action object
|
||||||
|
*
|
||||||
|
* @param name shown in the Menu
|
||||||
|
* @param action to call when activate the entry
|
||||||
|
*/
|
||||||
|
MenuAction(const char* name, MenuActionWrapper* action);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Construct a new Menu Action object
|
* @brief Construct a new Menu Action object
|
||||||
*
|
*
|
||||||
@@ -83,6 +97,7 @@ class MenuAction {
|
|||||||
|
|
||||||
bool isMenu = false;
|
bool isMenu = false;
|
||||||
MenuControl* menu = nullptr;
|
MenuControl* menu = nullptr;
|
||||||
|
MenuActionWrapper* action = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MENU_ENTRY_H
|
#endif // MENU_ENTRY_H
|
||||||
|
|||||||
Reference in New Issue
Block a user