Classes Reference
This page provides detailed documentation for all public classes in the EasyMenu library.
EasyMenu Class
Header: EasyMenu.h
The EasyMenu class is the primary interface for creating and managing interactive console menus. It provides methods for adding items, customizing appearance, and displaying the menu to users.
Constructors
EasyMenu()
EasyMenu()
Creates an empty menu without a default header or footer.
Example:
EasyMenu menu;
menu.AddItem("Item 1");
menu.AddItem("Item 2");
EasyMenu(const std::string& MenuLabel)
EasyMenu(const std::string& MenuLabel)
Creates a menu with a default header displaying the menu label and a default footer.
Parameters:
MenuLabel- The title/label for the menu, displayed in the default header
Example:
EasyMenu menu("Main Menu");
// Automatically includes a formatted header with "Main Menu"
Menu Execution
RunMenu()
unsigned int RunMenu(unsigned int ItemToStartFrom = 1)
Displays the menu and allows the user to navigate and select an item. This method blocks until the user makes a selection.
Parameters:
ItemToStartFrom- (Optional) The item number to highlight when the menu first appears. Defaults to 1 (first item).
Returns:
- The 1-based index of the selected item (1, 2, 3, ...)
0if the menu is empty or contains no navigable items
Example:
unsigned int choice = menu.RunMenu();
if (choice == 0) {
std::cout << "Menu is empty" << std::endl;
} else {
std::cout << "Selected: " << choice << std::endl;
}
// Start with the third item highlighted
unsigned int choice2 = menu.RunMenu(3);
Item Management
AddItem()
void AddItem(const std::string& Label, bool Active = true, bool Visible = true)
Adds a new item to the end of the menu.
Parameters:
Label- The text to display for this itemActive- (Optional) Whether the item can be selected. Defaults totrueVisible- (Optional) Whether the item is displayed. Defaults totrue
Example:
menu.AddItem("Play"); // Active and visible
menu.AddItem("Options", true, true); // Explicitly active and visible
menu.AddItem("Coming Soon", false, true); // Visible but not selectable
menu.AddItem("Debug", true, false); // Hidden item
UpdateItem()
bool UpdateItem(size_t ItemNumber, const std::string& Label, bool Active = true, bool Visible = true)
Updates an existing menu item with new properties.
Parameters:
ItemNumber- The 1-based index of the item to updateLabel- The new text for the itemActive- (Optional) Whether the item can be selectedVisible- (Optional) Whether the item is displayed
Returns:
trueif the update was successfulfalseif the item number is out of range
Example:
if (menu.UpdateItem(2, "Updated Label", true, true)) {
std::cout << "Item updated" << std::endl;
} else {
std::cout << "Item does not exist" << std::endl;
}
RemoveItem()
bool RemoveItem(size_t ItemNumber)
Removes an item from the menu. Subsequent items shift down to fill the gap.
Parameters:
ItemNumber- The 1-based index of the item to remove
Returns:
trueif the item was removedfalseif the item number is out of range
Example:
if (menu.RemoveItem(3)) {
std::cout << "Item 3 removed" << std::endl;
}
SetVisibility()
bool SetVisibility(size_t ItemNumber, bool Visible)
Shows or hides a specific menu item.
Parameters:
ItemNumber- The 1-based index of the itemVisible-trueto show the item,falseto hide it
Returns:
trueif the visibility was changedfalseif the item number is out of range
Example:
// Hide item 4
menu.SetVisibility(4, false);
// Show item 4
menu.SetVisibility(4, true);
SetActivity()
bool SetActivity(size_t ItemNumber, bool Active)
Makes an item selectable or non-selectable. Inactive items are still visible but cannot be chosen.
Parameters:
ItemNumber- The 1-based index of the itemActive-trueto make selectable,falseto disable
Returns:
trueif the activity state was changedfalseif the item number is out of range
Example:
// Disable item 2 (visible but not selectable)
menu.SetActivity(2, false);
// Enable item 2
menu.SetActivity(2, true);
ClearItems()
void ClearItems()
Removes all items from the menu.
Example:
menu.ClearItems();
// Menu now has no items
Header and Footer Management
SetHeader()
void SetHeader(const EasyMenuComponents::clsEasyMenuHeader& Header)
Sets a custom header for the menu.
Parameters:
Header- A custom header object created usingEasyMenuComponents::clsEasyMenuHeader
Example:
#include <EasyMenuComponents.h>
EasyMenuComponents::clsEasyMenuHeader header;
header.AddLine("======================");
header.AddLine(" Custom Application");
header.AddLine("======================");
menu.SetHeader(header);
GetHeader()
const EasyMenuComponents::clsEasyMenuHeader& GetHeader() const
Retrieves the current header object.
Returns:
- A const reference to the menu's header
SetFooter()
void SetFooter(const EasyMenuComponents::clsEasyMenuFooter& Footer)
Sets a custom footer for the menu.
Parameters:
Footer- A custom footer object created usingEasyMenuComponents::clsEasyMenuFooter
Example:
#include <EasyMenuComponents.h>
EasyMenuComponents::clsEasyMenuFooter footer;
footer.AddLine("======================");
footer.AddLine("Press Enter to select");
footer.AddLine("======================");
menu.SetFooter(footer);
GetFooter()
const EasyMenuComponents::clsEasyMenuFooter& GetFooter() const
Retrieves the current footer object.
Returns:
- A const reference to the menu's footer
ClearHeader()
void ClearHeader()
Removes the header from the menu.
Example:
menu.ClearHeader();
// Menu now has no header
ClearFooter()
void ClearFooter()
Removes the footer from the menu.
Example:
menu.ClearFooter();
// Menu now has no footer
ClearMenu()
void ClearMenu()
Removes all items, the header, and the footer from the menu, resetting it to an empty state.
Example:
menu.ClearMenu();
// Menu is now completely empty
Menu Inspection
GetNumberOfItems()
size_t GetNumberOfItems() const
Returns the total number of items in the menu, including hidden and inactive items.
Returns:
- The number of items
Example:
std::cout << "Menu has " << menu.GetNumberOfItems() << " items" << std::endl;
IsEmpty()
bool IsEmpty() const
Checks whether the menu has any items.
Returns:
trueif the menu has no itemsfalseif the menu has at least one item
Example:
if (menu.IsEmpty()) {
std::cout << "Please add items to the menu" << std::endl;
}
EasyMenuComponents::clsEasyMenuHeader
Header: EasyMenuComponents.h
This class represents a custom header for a menu. A header consists of multiple lines of text displayed at the top of the menu.
Static Methods
GetDefaultHeader()
static clsEasyMenuHeader GetDefaultHeader(const std::string& Label = "Easy Menu")
Creates a default header with a label.
Parameters:
Label- (Optional) The text to display in the header. Defaults to "Easy Menu"
Returns:
- A header object with formatted default styling
Example:
auto header = EasyMenuComponents::clsEasyMenuHeader::GetDefaultHeader("My App");
menu.SetHeader(header);
Instance Methods
AddLine()
void AddLine(const std::string& Line)
Adds a line of text to the header.
Parameters:
Line- The text to add
Example:
EasyMenuComponents::clsEasyMenuHeader header;
header.AddLine("====================");
header.AddLine(" Welcome!");
header.AddLine("====================");
menu.SetHeader(header);
EasyMenuComponents::clsEasyMenuFooter
Header: EasyMenuComponents.h
This class represents a custom footer for a menu. A footer consists of multiple lines of text displayed at the bottom of the menu.
Static Methods
GetDefaultFooter()
static clsEasyMenuFooter GetDefaultFooter()
Creates a default footer with standard formatting.
Returns:
- A footer object with default styling
Example:
auto footer = EasyMenuComponents::clsEasyMenuFooter::GetDefaultFooter();
menu.SetFooter(footer);
Instance Methods
AddLine()
void AddLine(const std::string& Line)
Adds a line of text to the footer.
Parameters:
Line- The text to add
Example:
EasyMenuComponents::clsEasyMenuFooter footer;
footer.AddLine("====================");
footer.AddLine("Use arrows to navigate");
footer.AddLine("====================");
menu.SetFooter(footer);
Complete Example
Here's a comprehensive example using multiple API features:
#include <iostream>
#include <EasyMenu.h>
#include <EasyMenuComponents.h>
int main() {
// Create menu with custom header
EasyMenu menu;
EasyMenuComponents::clsEasyMenuHeader header;
header.AddLine("========================");
header.AddLine(" Game Settings Menu");
header.AddLine("========================");
menu.SetHeader(header);
// Add items with different states
menu.AddItem("Video Settings");
menu.AddItem("Audio Settings");
menu.AddItem("Controls");
menu.AddItem("Multiplayer", false, true); // Inactive
menu.AddItem("Apply Changes");
menu.AddItem("Back");
// Check menu state
std::cout << "Menu has " << menu.GetNumberOfItems()
<< " items" << std::endl;
// Run menu starting from item 1
unsigned int choice = menu.RunMenu(1);
if (choice == 0) {
std::cout << "No selection made" << std::endl;
} else {
std::cout << "Selected option: " << choice << std::endl;
// Handle specific choices
switch (choice) {
case 1:
std::cout << "Opening video settings..." << std::endl;
break;
case 5:
std::cout << "Applying changes..." << std::endl;
break;
case 6:
std::cout << "Returning to main menu..." << std::endl;
break;
}
}
return 0;
}