docs/src/widgets/menu.rst
.. _lv_menu:
Overview
The Menu Widget can be used to create multi-level menus that automatically handle navigation among menu levels, and enable its user to capture page navigation and click events.
.. _lv_menu_parts_and_styles:
Parts and Styles
The Menu Widget is built from the following Widgets:
lv_menu_main_contlv_menu_main_header_contlv_buttonlv_imagelv_menu_pagelv_menu_sidebar_contlv_menu_sidebar_header_contlv_buttonlv_imagelv_menu_page.. _lv_menu_usage:
Usage
:cpp:expr:lv_menu_create(parent) creates a new empty Menu.
This creates a Menu Widget with this object hierarchy:
Menu: :cpp:type:lv_menu_t
Hidden Sub-Page Storage: :cpp:type:lv_obj_t
Main container: :cpp:var:lv_menu_main_cont_class
Main header: :cpp:var:lv_menu_main_header_cont_class
Back button: :ref:lv_button
lv_imageMain header title: :ref:lv_label (default hidden)
Note that no sidebar is created. You can create one later if you wish.
The following header modes exist:
LV_MENU_HEADER_TOP_FIXED Header is positioned at the top. (default)LV_MENU_HEADER_TOP_UNFIXED Header is positioned at the top and can be scrolled out of view.LV_MENU_HEADER_BOTTOM_FIXED Header is positioned at the bottom.You can set header modes with :cpp:expr:lv_menu_set_mode_header(menu, LV_MENU_HEADER...).
The following root back button modes exist:
LV_MENU_ROOT_BACK_BTN_DISABLED (default)LV_MENU_ROOT_BACK_BTN_ENABLEDYou can set root back button modes with
:cpp:expr:lv_menu_set_mode_root_back_button(menu, LV_MENU_ROOT_BACK_BTN...).
:cpp:expr:lv_menu_page_create(menu, title) creates a new empty Menu Page. You
can add any Widgets to the Page.
Once a Menu Page has been created, you can set it to the main area with
:cpp:expr:lv_menu_set_page(menu, page). NULL to clear main and clear Menu
history.
Once a Menu Page has been created, you can set it to the sidebar with
:cpp:expr:lv_menu_set_sidebar_page(menu, page). NULL to clear sidebar.
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
:cpp:expr:lv_menu_set_load_page_event(menu, btn, new page).
The following objects can be created so that it is easier to style the Menu:
lv_menu_cont_create(parent_page) creates a new empty container.lv_menu_section_create(parent_page) creates a new empty section.lv_menu_separator_create(parent_page) creates a separator... _lv_menu_events:
Events
:cpp:enumerator:LV_EVENT_VALUE_CHANGED Sent when a Page is shown.
lv_menu_get_cur_main_page(menu) returns a pointer to Menu Page
that is currently displayed in the main container.lv_menu_get_cur_sidebar_page(menu) returns a pointer to Menu
Page that is currently displayed in the sidebar container.:cpp:enumerator:LV_EVENT_CLICKED Sent when a back button in a header from either
main or sidebar is clicked. :cpp:enumerator:LV_OBJ_FLAG_EVENT_BUBBLE is enabled
on the buttons so you can add events to the Menu itself.
lv_menu_back_button_is_root(menu, button) to check if button is root
back button... admonition:: Further Reading
Learn more about :ref:`lv_obj_events` emitted by all Widgets.
Learn more about :ref:`events`.
.. _lv_menu_keys:
Keys
No Keys are processed by Menu Widgets.
.. admonition:: Further Reading
Learn more about :ref:`indev_keys`.
.. _lv_menu_example:
Examples
.. include:: /examples/widgets/menu/index.rst
.. _lv_menu_api:
API