1# Menu (lv_menu)
2
3## Overview
4The menu widget can be used to easily create multi-level menus. It handles the traversal between pages automatically.
5
6## Parts and Styles
7The menu widget is built from the following objects:
8- Main container: lv_menu_main_cont
9  - Main header: lv_menu_main_header_cont
10    - Back btn: [lv_btn](/widgets/core/btn)
11      - Back btn icon: [lv_img](/widgets/core/img)
12  - Main page: lv_menu_page
13- Sidebar container: lv_menu_sidebar_cont
14  - Sidebar header: lv_menu_sidebar_header_cont
15    - Back btn: [lv_btn](/widgets/core/btn)
16      - Back btn icon: [lv_img](/widgets/core/img)
17  - Sidebar page: lv_menu_page
18
19## Usage
20
21### Create a menu
22`lv_menu_create(parent)` creates a new empty menu.
23
24### Header mode
25The following header modes exist:
26- `LV_MENU_HEADER_TOP_FIXED` Header is positioned at the top.
27- `LV_MENU_HEADER_TOP_UNFIXED` Header is positioned at the top and can be scrolled out of view.
28- `LV_MENU_HEADER_BOTTOM_FIXED` Header is positioned at the bottom.
29
30You can set header modes with `lv_menu_set_mode_header(menu, LV_MENU_HEADER...)`.
31
32### Root back button mode
33The following root back button modes exist:
34- `LV_MENU_ROOT_BACK_BTN_DISABLED`
35- `LV_MENU_ROOT_BACK_BTN_ENABLED`
36
37You can set root back button modes with `lv_menu_set_mode_root_back_btn(menu, LV_MENU_ROOT_BACK_BTN...)`.
38
39### Create a menu page
40`lv_menu_page_create(menu, title)` creates a new empty menu page.
41You can add any widgets to the page.
42
43### Set a menu page in the main area
44Once 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.
45
46### Set a menu page in the sidebar
47Once 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.
48
49### Linking between menu pages
50For instance, you have created a btn obj in the main page. When you click the btn obj, you want it to open up a new page, use `lv_menu_set_load_page_event(menu, obj, new page)`.
51
52### Create a menu container, section, separator
53The following objects can be created so that it is easier to style the menu:
54
55`lv_menu_cont_create(parent page)` creates a new empty container.
56
57`lv_menu_section_create(parent page)` creates a new empty section.
58
59`lv_menu_separator_create(parent page)` creates a separator.
60
61## Events
62- `LV_EVENT_VALUE_CHANGED` Sent when a page is shown.
63  - `lv_menu_get_cur_main_page(menu)` returns a pointer to menu page that is currently displayed in main.
64  - `lv_menu_get_cur_sidebar_page(menu)` returns a pointer to menu page that is currently displayed in sidebar.
65- `LV_EVENT_CLICKED` Sent when a back btn in a header from either main or sidebar is clicked. `LV_OBJ_FLAG_EVENT_BUBBLE` is enabled on the buttons so you can add events to the menu itself.
66  - `lv_menu_back_btn_is_root(menu, btn)` to check if btn is root back btn
67
68See the events of the [Base object](/widgets/obj) too.
69
70Learn more about [Events](/overview/event).
71
72## Keys
73No keys are handled by the menu widget.
74
75Learn more about [Keys](/overview/indev).
76
77
78## Example
79
80```eval_rst
81.. include:: ../../../examples/widgets/menu/index.rst
82```
83
84## API
85
86```eval_rst
87.. doxygenfile:: lv_menu.h
88  :project: lvgl
89
90```