Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/The-Young-Maker/OpenMenuOS/llms.txt

Use this file to discover all available pages before exploring further.

MenuScreen renders a vertically scrollable list of selectable items. Each item can link to another Screen, execute a callback function, display an icon image, or any combination of the three. Menus resize automatically to the display dimensions and support unlimited nesting depth.

Constructors

Creates a menu screen without a title.
MenuScreen mainMenu;
Creates a menu screen with the given title, displayed in the header bar.
title
const char*
required
Title string shown at the top of the screen.
MenuScreen mainMenu("Main Menu");

Item management

addItem(const char* label, Screen* nextScreen, ActionCallback action, const uint16_t* image)

Adds an item to the menu with an explicit label. All parameters after label are optional.
label
const char*
required
Display text shown for the menu item.
nextScreen
Screen*
default:"nullptr"
Screen to push onto the navigation stack when the item is selected. Pass nullptr if no navigation is needed.
action
ActionCallback
default:"nullptr"
Function pointer (void (*)()) called when the item is selected. Runs before navigating to nextScreen if both are provided.
image
const uint16_t*
default:"nullptr"
Pointer to a raw RGB565 image array displayed as an icon beside the label.
// Label only (non-interactive placeholder)
mainMenu.addItem("First Test Page");

// Navigate to a sub-screen
mainMenu.addItem("Settings", &settingsScreen);

// Trigger a callback
mainMenu.addItem("About", nullptr, showAbout);

// Navigate and show an icon
mainMenu.addItem("Settings", &settingsScreen, nullptr, (const uint16_t*)Menu_icon_1);

addItem(Screen* nextScreen, ActionCallback action, const uint16_t* image)

Adds an item whose label is automatically taken from nextScreen->getTitle(). Useful for keeping item labels and screen titles in sync without duplicating strings.
nextScreen
Screen*
required
Target screen. Its title is used as the item label.
action
ActionCallback
default:"nullptr"
Optional callback executed on selection.
image
const uint16_t*
default:"nullptr"
Optional icon image pointer.
MenuScreen testScreen("Test Menu");
CustomScreen customScreen("Custom Screen");

// Label is auto-populated as "Test Menu"
mainMenu.addItem(&testScreen);

// Label is "Custom Screen"
testScreen.addItem(&customScreen);

clearItems()

Removes all items from the menu. Use this to rebuild a menu dynamically at runtime.
void updateMenu(bool wifiConnected) {
  mainMenu.clearItems();

  if (wifiConnected) {
    mainMenu.addItem("Network Settings", &networkMenu);
  } else {
    mainMenu.addItem("Connect WiFi", nullptr, connectWiFi);
  }

  mainMenu.addItem("Local Settings", &localSettings);
}

getIndex()

Returns the zero-based index of the currently highlighted item. Returns: int
int selected = mainMenu.getIndex();

Public properties

These members are publicly accessible on every MenuScreen instance.
MemberTypeDescription
titleconst char*Title string passed to the constructor.
itemsstd::vector<MenuItem>Ordered collection of all added items.
currentItemIndexintZero-based index of the currently selected item.
itemSizeintTotal number of items in the menu.

Each entry in items is a MenuItem with the following fields:
FieldTypeDescription
labelconst char*Display text for the item.
nextScreenScreen*Screen navigated to on selection, or nullptr.
actionActionCallbackCallback function invoked on selection, or nullptr.
imageconst uint16_t*RGB565 icon image pointer, or nullptr.

Complete example

The following sketch builds a two-level menu with action callbacks and an icon.
#include "OpenMenuOS.h"
#include "images.h"

OpenMenuOS menu(19, 18, 2); // UP, DOWN, SELECT

MenuScreen mainMenu("Smart Device");
MenuScreen deviceMenu("Device Control");
SettingsScreen settingsScreen("Settings");
CustomScreen aboutScreen("About");

bool ledState = false;

void toggleLED() {
  ledState = !ledState;
  digitalWrite(LED_BUILTIN, ledState);
}

void setup() {
  // Build the device sub-menu
  deviceMenu.addItem("Toggle LED", nullptr, toggleLED);
  deviceMenu.addItem("Device Status", nullptr, showStatus);

  // Build the main menu
  // addItem with explicit label and icon
  mainMenu.addItem("Settings", &settingsScreen, nullptr, (const uint16_t*)Menu_icon_1);
  // addItem auto-uses deviceMenu.title ("Device Control")
  mainMenu.addItem(&deviceMenu);
  // addItem with callback only
  mainMenu.addItem("Reboot", nullptr, []() { ESP.restart(); });
  // addItem linking to a CustomScreen
  mainMenu.addItem("About", &aboutScreen);

  menu.useStylePreset("Rabbit_R1");
  menu.begin(&mainMenu);
}

void loop() {
  menu.loop();
}
Items added with addItem(Screen* nextScreen) automatically reflect any change to the target screen’s title — you do not need to update the label string separately.

Build docs developers (and LLMs) love