Files
Menu/include/menuAction.h
T
2023-10-12 19:50:26 +02:00

114 lines
2.4 KiB
C++

/**
* @file menuAction.h
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains the MenuAction class
* @version 0.1
* @date 2022-01-12
*
* @copyright Copyright (c) 2022
*
*/
#ifndef MENU_ENTRY_H
#define MENU_ENTRY_H
#include "menu.h"
class MenuControl;
/**
* @brief An Interface to execute actions
*
* This interface can be inherited to wrap actions
* in it for a MenuAction.
*/
class MenuActionWrapper
{
public:
virtual ~MenuActionWrapper() {}
/**
* @brief Function to be called by the MenuAction
*/
virtual void action() = 0;
};
/**
* @brief This class forms the transition between menus.
*
* In the Menu these are the entries.
* This class can be call an submenu or a function.
*/
class MenuAction
{
public:
/**
* @brief Construct a new Menu Action object
*
* @param name shown in the Menu
* @param function to call when activate the entry
* @param callback to call when leave the entry
*/
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
*
* This constructor is used for submenus.
*
* @param name shown in the Menu
* @param menu to call when activate the entry
*/
MenuAction(const char *name, MenuControl *menu);
~MenuAction();
/**
* @brief activates the entry
*/
void runAction();
/**
* @brief Get the Name string
*
* @return const char*
*/
const char *getName();
/**
* @brief Get the Is Menu object
*
* @return true runAction calls a submenu
* @return false runAction call a function
*/
bool getIsMenu();
/**
* @brief Get the Menu object
*
* Before call this function it may be useful
* to check if is it a submenu with getIsMenu.
*
* @return MenuControl*
*/
MenuControl *getMenu();
private:
const char *name;
void (*function)() = nullptr;
void (*callback)() = nullptr;
bool isMenu = false;
MenuControl *menu = nullptr;
MenuActionWrapper *action = nullptr;
};
#endif // MENU_ENTRY_H