Skip to content
Logo LogoLcdMenu
Docs Changelog License
⌘ K
Logo LogoLcdMenu
Docs Changelog License

Overview

  • Getting started
  • Menu Screen
  • Item overview
    • Basic menu item
    • Value display item
    • Command menu item
    • Sub-menu item
    • Item Widget
    • Item List
    • Item Range
    • Item Bool
    • Input item
    • Charset input item
  • Widget overview
    • WidgetBool
    • WidgetList
    • WidgetRange
  • Controlling the menu
    • Keyboard Adapter
    • Button Adapter
    • Rotary Encoder Adapter
    • Analog Button Adapter
  • Rendering the menu
    • Character display renderer

Reference

  • Code samples
    • InputRotary
    • SubMenu
    • SimpleRotary
    • IntFloatValues
    • SimpleInput
    • KeyboardAdapter
    • pcf8574_i2c
    • ItemValue
    • RTOS
    • KeypadShield
    • ViewShifting
    • MenuTimeout
    • DynamicMenu
    • ButtonWithRotaryAdapter
    • UseByRef
    • List
    • ItemBack
    • Basic
    • Widgets
    • Callbacks
    • CharsetInput
    • SSD1803A_I2C
    • ButtonAdapter
  • API reference
    • MenuItem
    • ItemCommand
    • MenuScreen
    • ItemBool
    • ItemInput
    • ItemSubMenu
    • ItemToggle
    • ItemInputCharset
    • ItemValue
    • ItemWidget
    • ItemRange
    • BaseItemManyWidgets
    • ItemList
    • ItemBack
    • LcdMenu
    • BaseItemZeroWidget
    • renderer
    • input
    • display
    • widget
  • Migration
  • FAQ

Star on GitHub
Edit on GitHub
Arduino Library Badge PlatformIO Badge Check Runs Badge Documentation Status Badge GitHub Commits Badge

LcdMenu
/
Menu Screen

Menu Screen

The MenuScreen class is the foundation of the LcdMenu library’s menu system. It represents a single screen in the menu hierarchy and is responsible for managing a collection of menu items (MenuItem), handling navigation, and rendering the menu on the display.

With MenuScreen, you can create dynamic, hierarchical menus that allow users to interact with your embedded application in an intuitive way. Whether you’re building a simple menu or a complex multi-level menu system, MenuScreen provides the tools you need.

Why Use MenuScreen?

The MenuScreen class simplifies the process of creating and managing menus in embedded systems. It provides:

  1. Dynamic Menu Management: - Add, remove, or update menu items at runtime. - Create menus that adapt to user input or application state.

  2. Hierarchical Navigation: - Easily create submenus and navigate between them using the BACK and RIGHT commands. - Set parent screens for seamless navigation.

  3. Cursor and View Management: - Automatically handles cursor movement and ensures only the visible portion of the menu is displayed.

  4. Integration with Renderers: - Works seamlessly with MenuRenderer to display menus on various types of displays.

  5. Polling for Updates: - Supports periodic updates for menu items that require dynamic behavior, such as real-time data or animations.

How to Use MenuScreen

Creating a MenuScreen

To create a MenuScreen, you define a list of MenuItem objects and pass them to the MenuScreen constructor. The MENU_SCREEN macro simplifies this process.

MENU_SCREEN(mainScreen, mainItems,
    new MenuItem("Option 1"),
    new MenuItem("Option 2"),
    new MenuItem("Option 3")
);

In this example: - A MenuScreen named mainScreen is created. - It contains three menu items: “Option 1”, “Option 2”, and “Option 3”.

Navigating Between Screens

You can create hierarchical menus by linking screens together. For example, you can set a parent screen for a submenu:

MENU_SCREEN(subScreen, subItems,
    new MenuItem("Sub Option 1"),
    new MenuItem("Sub Option 2")
);

subScreen->setParent(mainScreen);

When the user navigates back from subScreen, they will return to mainScreen.

Adding and Removing Items Dynamically

You can modify the menu at runtime by adding or removing items:

mainScreen->addItem(new MenuItem("New Option"));
mainScreen->removeItemAt(1);  // Removes the second item

This is useful for creating menus that adapt to the application’s state or user input.

Polling for Updates

If your menu items require periodic updates (e.g., displaying real-time data), you can use the poll method:

lcd->poll(1000);  // Poll every 1000ms

This ensures that the menu is updated at regular intervals.

Examples

For complete examples of using MenuScreen, see the following:

  • Dynamic Menu Example: Demonstrates how to dynamically add, remove, and update menu items at runtime.

  • Submenu Example: Shows how to create hierarchical menus with parent-child relationships.

  • Polling Example and Polling Example: Explains how to use the poll method for dynamic updates.

Notes

  • Ensure that the MenuItem objects passed to a MenuScreen remain valid for the lifetime of the screen.

  • Use the poll method for menu items that require dynamic updates, such as real-time data or animations.

  • The MenuScreen class is designed to work seamlessly with the LcdMenu and MenuRenderer classes for rendering and input handling.

Summary

The MenuScreen class is a powerful tool for creating dynamic, hierarchical menus in embedded systems. By combining MenuScreen with other components of the LcdMenu library, you can build intuitive and flexible user interfaces for your applications.

For more details, refer to the API Reference or explore the examples linked above.

Getting started
Item overview

On this page

  • Why Use MenuScreen?
  • How to Use MenuScreen
    • Creating a MenuScreen
    • Navigating Between Screens
    • Adding and Removing Items Dynamically
    • Polling for Updates
  • Examples
  • Notes
  • Summary

© 2025, Thomas Forntoh