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->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();
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
|
||||
class MenuControl;
|
||||
|
||||
class MenuActionWrapper {
|
||||
public:
|
||||
virtual ~MenuActionWrapper() {}
|
||||
virtual void action() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This class forms the transition between menus.
|
||||
*
|
||||
@@ -33,6 +39,14 @@ class MenuAction {
|
||||
*/
|
||||
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
|
||||
*
|
||||
@@ -83,6 +97,7 @@ class MenuAction {
|
||||
|
||||
bool isMenu = false;
|
||||
MenuControl* menu = nullptr;
|
||||
MenuActionWrapper* action = nullptr;
|
||||
};
|
||||
|
||||
#endif // MENU_ENTRY_H
|
||||
|
||||
Reference in New Issue
Block a user