Menu (lv_menu)

Multi-level menu widget. Handles navigation between pages automatically and reports page changes and clicks.

Edit on GitHub

Overview

Deprecated

The lv_menu widget is deprecated and kept only for backward compatibility. A menu is page navigation over base widgets — pages built from lv_obj and a back button that swaps the visible page — so build it directly instead. See the lv_example_menu_navigation example for a starting point.

The Menu widget builds multi-level menus. It handles navigation between pages automatically and lets you react to page changes and item clicks.

Styling

A Menu is made of standard building blocks — a main container, an optional sidebar, headers, back buttons, and one or more pages. Each block is a regular widget, so styling follows the same rules as Base Widget, Button, and Image. See Create a Menu below for the full tree.

Create a Menu

lv_menu_create(parent) creates a new empty Menu.

This creates a Menu Widget with this object hierarchy:

Note that no sidebar is created. You can create one later if you wish.

Header mode

The following header modes exist:

You can set header modes with lv_menu_set_mode_header(menu, LV_MENU_HEADER...).

Root back button mode

The following root back button modes exist:

  • LV_MENU_ROOT_BACK_BTN_DISABLED (default)
  • LV_MENU_ROOT_BACK_BTN_ENABLED

You can set root back button modes with lv_menu_set_mode_root_back_button(menu, LV_MENU_ROOT_BACK_BTN...).

Create a Menu Page

lv_menu_page_create(menu, title) creates a new empty Menu Page. You can add any Widgets to the Page.

Set a Menu Page in the main area

Once a Menu Page has been created, you can set it to the main area with lv_menu_set_page(menu, page). NULL to clear main and clear Menu history.

Set a Menu Page in the sidebar

Once a Menu Page has been created, you can set it to the sidebar with lv_menu_set_sidebar_page(menu, page). NULL to clear sidebar.

Linking between Menu Pages

If you have, for instance, created a button obj in the main Page. When you click the button Widget, you want it to open up a new Page, use lv_menu_set_load_page_event(menu, btn, new page).

Create a Menu container, section, separator

The following objects can be created so that it is easier to style the Menu:

Events

Learn more about Events emitted by all Widgets.

Building a menu without lv_menu

Since lv_menu is deprecated, this example shows the recommended approach: pages are lv_obj containers stacked in a content area, only one shown at a time by toggling LV_OBJ_FLAG_HIDDEN. A header back button returns to the root page. The small menu_* helpers mirror the parts of the old API you actually need.

Examples

Deprecated

The examples below use the deprecated lv_menu widget. Prefer the approach in Building a menu without lv_menu for new code.

Simple Menu

Simple Menu with root btn

Simple Menu with custom header

Simple Menu with floating btn to add new menu page

Complex Menu

Last updated on

On this page