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:

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:

Returns:

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:

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:

Returns:

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:

Returns:

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:

Returns:

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:

Returns:

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:

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:

SetFooter()

void SetFooter(const EasyMenuComponents::clsEasyMenuFooter& Footer)

Sets a custom footer for the menu.

Parameters:

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:

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:

Example:

std::cout << "Menu has " << menu.GetNumberOfItems() << " items" << std::endl;

IsEmpty()

bool IsEmpty() const

Checks whether the menu has any items.

Returns:

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:

Returns:

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:

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:

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:

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;
}