Contents Menu Expand Light mode Dark mode System, in dark mode System, in light mode View documentation source on GitHub Skip to content
LVGL 9.3 documentation
Light Logo Dark Logo
  • Introduction
  • Getting Started
  • Examples
  • Integration and Drivers
    • Adding LVGL to Your Project
      • Getting LVGL
      • Building LVGL
      • Configuration
      • Connecting LVGL to Your Hardware
      • Timer Handler
      • Threading Considerations
      • Other Platforms and Tools
    • Bindings
      • Output API as JSON Data
      • Cpp
      • JavaScript
      • MicroPython
      • PikaScript
    • Build Systems
      • make
      • CMake
    • Chip vendors
      • Alif
      • Arm
      • Espressif (ESP32 Chip Series)
      • NXP
      • Renesas
        • Built-in Drivers
        • RA Family
        • RX Family
        • RZ/G Family
        • RZ/A Family
        • Supported Boards
      • STM32
    • Drivers
      • Display
        • Linux Framebuffer Driver
        • FT81x
        • Generic MIPI DCS compatible LCD Controller driver
        • ILI9341 LCD Controller driver
        • Step-by-step Guide: How to use the LVGL v9 LCD drivers with STM32 devices
        • NXP eLCDIF
        • Renesas GLCDC
        • STM32 LTDC Driver
        • ST7735 LCD Controller driver
        • ST7789 LCD Controller driver
        • ST7796 LCD Controller driver
      • Libinput Driver
      • OpenGL ES Display/Inputs Driver
      • Touchpad
        • Linux Evdev Driver
        • FT6X36
      • Wayland Display/Inputs driver
      • Windows Display/Inputs driver
      • X11 Display/Inputs driver
      • UEFI Display/Inputs driver
      • SDL Driver
    • Renderers and GPUs
      • Software Renderer
      • Arm-2D GPU
      • Espressif Pixel Processing Accelerator
      • NemaGFX Acceleration
      • NXP PXP GPU
      • NXP VGLite GPU
      • NXP G2D GPU
      • SDL Renderer
      • STM32 DMA2D GPU
      • VG-Lite General GPU
    • Frameworks
      • Arduino
      • PlatformIO
      • Tasmota and berry
    • IDEs
      • MDK
      • Simulator on PC
    • (RT)OS
      • FreeRTOS
      • MQX RTOS
      • NuttX RTOS
      • PX5 RTOS
      • QNX
      • RT-Thread RTOS
      • Yocto
        • Yocto Project Core Components
        • LVGL in Yocto
        • Yocto Project Terms
      • Buildroot
        • Quick Setup
        • RPi4 custom image
        • LVGL application
      • Zephyr
      • Torizon OS
    • Boards
      • Toradex
      • Riverdi
      • Viewe
  • Common Widget Features
    • Widget Basics
    • Positions, Sizes and Layouts
    • Layers
    • Styles
      • Styles Overview
      • Style Properties
    • Events
    • Layouts
      • Flex
      • Grid
    • Scrolling
  • All Widgets
    • Base Widget (lv_obj)
    • 3D Texture (lv_3dtexture)
    • Animation Image (lv_animimg)
    • Arc (lv_arc)
    • Arc Label (lv_arclabel)
    • Bar (lv_bar)
    • Button (lv_button)
    • Button Matrix (lv_buttonmatrix)
    • Calendar (lv_calendar)
    • Canvas (lv_canvas)
    • Chart (lv_chart)
    • Checkbox (lv_checkbox)
    • Drop-Down List (lv_dropdown)
    • Image (lv_image)
    • Image Button (lv_imagebutton)
    • Keyboard (lv_keyboard)
    • Label (lv_label)
    • LED (lv_led)
    • Line (lv_line)
    • List (lv_list)
    • Lottie (lv_lottie)
    • Menu (lv_menu)
    • Message Box (lv_msgbox)
    • Roller (lv_roller)
    • Scale (lv_scale)
    • Slider (lv_slider)
    • Spangroup (lv_spangroup)
    • Spinbox (lv_spinbox)
    • Spinner (lv_spinner)
    • Switch (lv_switch)
    • Table (lv_table)
    • Tab View (lv_tabview)
    • Text Area (lv_textarea)
    • Tile View (lv_tileview)
    • Window (lv_win)
    • New Widget
  • Main Modules
    • Display (lv_display)
      • Overview
      • Setting Up Your Display(s)
      • Screen Layers
      • Color Format
      • Refreshing
      • Events
      • API
      • Changing Resolution
      • Inactivity Measurement
      • Rotation
      • Constraints on Redrawn Area
      • Tiled Rendering
      • Extending/Combining Displays
    • Input Device (lv_indev)
    • Color (lv_color)
    • Font (lv_font)
    • Images (lv_image)
    • Timer (lv_timer)
    • Animation (lv_anim)
    • File System (lv_fs_drv)
    • Drawing
      • Draw Pipeline
      • Draw API
      • Draw Layers
      • Draw Descriptors
  • Auxiliary Modules
    • File Explorer
    • Font Manager
    • Fragment
    • Grid navigation
    • Pinyin IME
    • Image font
    • Monkey
    • Widget ID
    • Widget Properties
    • Observer
      • How to Use
      • Examples
    • Snapshot
    • UI Testing
    • XML - Declarative UI
      • Introduction
      • Component Library
      • Project
      • Syntax
      • Components
      • Screens
      • Widgets
      • Preview
      • API
      • Styles
      • Constants
      • View
      • Fonts
      • Images
      • Events
      • Subjects
      • Animations
      • Translations
  • 3rd-Party Libraries
    • Arduino ESP littlefs
    • Arduino SD
    • Barcode
    • BMP Decoder
    • FFmpeg Support
    • FreeType Support
    • File System Interfaces
    • GIF Decoder
    • littlefs
    • libjpeg-turbo Decoder
    • libpng Decoder
    • LodePNG Decoder
    • QR Code
    • RLE Decompression
    • Rlottie Player
    • SVG Support
    • Tiny TTF font engine
    • Tiny JPEG Decompressor (TJpgDec)
  • Debugging
    • GDB Plug-In
    • Logging
    • Profiler
    • VG-Lite Simulator
  • Contributing
    • Introduction
    • Ways to Contribute
    • Pull Requests
    • Developer Certification of Origin (DCO)
    • Coding Style
  • Change Log
  • API
    • lv_conf_kconfig.h
    • lv_conf_internal.h
    • lv_api_map_v9_1.h
    • lvgl_private.h
    • lvgl.h
    • lv_api_map_v9_0.h
    • lv_api_map_v8.h
    • lv_init.h
    • stdlib
      • lv_string.h
      • lv_mem.h
      • lv_sprintf.h
      • lv_mem_private.h
      • builtin
        • lv_tlsf_private.h
        • lv_tlsf.h
    • core
      • lv_global.h
      • lv_obj_style_private.h
      • lv_obj_scroll_private.h
      • lv_obj_class.h
      • lv_obj_tree.h
      • lv_refr.h
      • lv_group_private.h
      • lv_obj_scroll.h
      • lv_obj_property.h
      • lv_obj_private.h
      • lv_obj_style.h
      • lv_obj_style_gen.h
      • lv_obj.h
      • lv_obj_draw_private.h
      • lv_obj_pos.h
      • lv_refr_private.h
      • lv_obj_event.h
      • lv_obj_event_private.h
      • lv_obj_draw.h
      • lv_obj_class_private.h
      • lv_group.h
    • osal
      • lv_mqx.h
      • lv_rtthread.h
      • lv_windows.h
      • lv_cmsis_rtos2.h
      • lv_os_private.h
      • lv_linux_private.h
      • lv_pthread.h
      • lv_os.h
      • lv_os_none.h
      • lv_freertos.h
      • lv_sdl2.h
    • themes
      • lv_theme_private.h
      • lv_theme.h
      • simple
        • lv_theme_simple.h
      • mono
        • lv_theme_mono.h
      • default
        • lv_theme_default.h
    • others
      • file_explorer
        • lv_file_explorer.h
        • lv_file_explorer_private.h
      • xml
        • lv_xml_private.h
        • lv_xml_component.h
        • lv_xml_parser.h
        • lv_xml.h
        • lv_xml_style.h
        • lv_xml_widget.h
        • lv_xml_utils.h
        • lv_xml_component_private.h
        • lv_xml_base_types.h
        • lv_xml_update.h
        • parsers
          • lv_xml_bar_parser.h
          • lv_xml_slider_parser.h
          • lv_xml_spangroup_parser.h
          • lv_xml_tabview_parser.h
          • lv_xml_dropdown_parser.h
          • lv_xml_button_parser.h
          • lv_xml_roller_parser.h
          • lv_xml_event_parser.h
          • lv_xml_keyboard_parser.h
          • lv_xml_obj_parser.h
          • lv_xml_calendar_parser.h
          • lv_xml_textarea_parser.h
          • lv_xml_checkbox_parser.h
          • lv_xml_label_parser.h
          • lv_xml_buttonmatrix_parser.h
          • lv_xml_arc_parser.h
          • lv_xml_chart_parser.h
          • lv_xml_scale_parser.h
          • lv_xml_canvas_parser.h
          • lv_xml_image_parser.h
          • lv_xml_table_parser.h
      • ime
        • lv_ime_pinyin.h
        • lv_ime_pinyin_private.h
      • fragment
        • lv_fragment.h
        • lv_fragment_private.h
      • gridnav
        • lv_gridnav.h
      • observer
        • lv_observer_private.h
        • lv_observer.h
      • monkey
        • lv_monkey_private.h
        • lv_monkey.h
      • test
        • lv_test_helpers.h
        • lv_test_indev.h
        • lv_test.h
        • lv_test_private.h
        • lv_test_indev_gesture.h
        • lv_test_display.h
        • lv_test_screenshot_compare.h
      • font_manager
        • lv_font_manager.h
        • lv_font_manager_recycle.h
      • snapshot
        • lv_snapshot.h
      • sysmon
        • lv_sysmon.h
        • lv_sysmon_private.h
      • imgfont
        • lv_imgfont.h
    • display
      • lv_display.h
      • lv_display_private.h
    • libs
      • lodepng
        • lv_lodepng.h
      • bmp
        • lv_bmp.h
      • barcode
        • lv_barcode.h
        • lv_barcode_private.h
      • rle
        • lv_rle.h
      • bin_decoder
        • lv_bin_decoder.h
      • qrcode
        • lv_qrcode.h
        • lv_qrcode_private.h
      • tiny_ttf
        • lv_tiny_ttf.h
      • svg
        • lv_svg_decoder.h
        • lv_svg_render.h
        • lv_svg_token.h
        • lv_svg_parser.h
        • lv_svg.h
      • tjpgd
        • lv_tjpgd.h
      • freetype
        • lv_freetype.h
        • lv_freetype_private.h
      • ffmpeg
        • lv_ffmpeg_private.h
        • lv_ffmpeg.h
      • libpng
        • lv_libpng.h
      • libjpeg_turbo
        • lv_libjpeg_turbo.h
      • rlottie
        • lv_rlottie.h
        • lv_rlottie_private.h
      • fsdrv
        • lv_fsdrv.h
      • gif
        • lv_gif.h
        • lv_gif_private.h
    • font
      • lv_font_fmt_txt_private.h
      • lv_binfont_loader.h
      • lv_symbol_def.h
      • lv_font.h
      • lv_font_fmt_txt.h
    • widgets
      • button
        • lv_button_private.h
        • lv_button.h
      • msgbox
        • lv_msgbox.h
        • lv_msgbox_private.h
      • arclabel
        • lv_arclabel_private.h
        • lv_arclabel.h
      • slider
        • lv_slider.h
        • lv_slider_private.h
      • list
        • lv_list.h
      • tileview
        • lv_tileview.h
        • lv_tileview_private.h
      • objx_templ
        • lv_objx_templ.h
      • label
        • lv_label.h
        • lv_label_private.h
      • menu
        • lv_menu.h
        • lv_menu_private.h
      • buttonmatrix
        • lv_buttonmatrix.h
        • lv_buttonmatrix_private.h
      • scale
        • lv_scale_private.h
        • lv_scale.h
      • textarea
        • lv_textarea_private.h
        • lv_textarea.h
      • line
        • lv_line.h
        • lv_line_private.h
      • 3dtexture
        • lv_3dtexture.h
        • lv_3dtexture_private.h
      • arc
        • lv_arc.h
        • lv_arc_private.h
      • span
        • lv_span.h
        • lv_span_private.h
      • win
        • lv_win.h
        • lv_win_private.h
      • calendar
        • lv_calendar_header_arrow.h
        • lv_calendar_private.h
        • lv_calendar.h
        • lv_calendar_header_dropdown.h
        • lv_calendar_chinese.h
      • canvas
        • lv_canvas_private.h
        • lv_canvas.h
      • animimage
        • lv_animimage_private.h
        • lv_animimage.h
      • property
        • lv_obj_property_names.h
        • lv_style_properties.h
      • switch
        • lv_switch_private.h
        • lv_switch.h
      • image
        • lv_image.h
        • lv_image_private.h
      • roller
        • lv_roller_private.h
        • lv_roller.h
      • table
        • lv_table_private.h
        • lv_table.h
      • dropdown
        • lv_dropdown_private.h
        • lv_dropdown.h
      • lottie
        • lv_lottie.h
        • lv_lottie_private.h
      • spinbox
        • lv_spinbox.h
        • lv_spinbox_private.h
      • led
        • lv_led_private.h
        • lv_led.h
      • tabview
        • lv_tabview.h
        • lv_tabview_private.h
      • bar
        • lv_bar.h
        • lv_bar_private.h
      • checkbox
        • lv_checkbox_private.h
        • lv_checkbox.h
      • spinner
        • lv_spinner.h
      • imagebutton
        • lv_imagebutton.h
        • lv_imagebutton_private.h
      • keyboard
        • lv_keyboard.h
        • lv_keyboard_private.h
      • chart
        • lv_chart_private.h
        • lv_chart.h
    • draw
      • lv_image_dsc.h
      • lv_draw.h
      • lv_draw_buf_private.h
      • lv_draw_3d.h
      • lv_draw_vector.h
      • lv_draw_arc.h
      • lv_draw_label_private.h
      • lv_draw_vector_private.h
      • lv_draw_private.h
      • lv_draw_image.h
      • lv_draw_rect_private.h
      • lv_draw_triangle_private.h
      • lv_image_decoder.h
      • lv_draw_mask.h
      • lv_draw_mask_private.h
      • lv_image_decoder_private.h
      • lv_draw_line.h
      • lv_draw_buf.h
      • lv_draw_rect.h
      • lv_draw_triangle.h
      • lv_draw_image_private.h
      • lv_draw_label.h
      • espressif
        • ppa
          • lv_draw_ppa_private.h
          • lv_draw_ppa.h
      • vg_lite
        • lv_vg_lite_grad.h
        • lv_vg_lite_stroke.h
        • lv_vg_lite_math.h
        • lv_draw_vg_lite.h
        • lv_draw_vg_lite_type.h
        • lv_vg_lite_path.h
        • lv_vg_lite_pending.h
        • lv_vg_lite_utils.h
        • lv_vg_lite_decoder.h
      • opengles
        • lv_draw_opengles.h
      • renesas
        • dave2d
          • lv_draw_dave2d.h
          • lv_draw_dave2d_utils.h
      • dma2d
        • lv_draw_dma2d.h
        • lv_draw_dma2d_private.h
      • sdl
        • lv_draw_sdl.h
      • sw
        • lv_draw_sw_utils.h
        • lv_draw_sw.h
        • lv_draw_sw_mask_private.h
        • lv_draw_sw_private.h
        • lv_draw_sw_grad.h
        • lv_draw_sw_mask.h
        • blend
          • lv_draw_sw_blend_to_rgb565.h
          • lv_draw_sw_blend_to_rgb888.h
          • lv_draw_sw_blend_to_l8.h
          • lv_draw_sw_blend_to_argb8888.h
          • lv_draw_sw_blend_to_rgb565_swapped.h
          • lv_draw_sw_blend_to_i1.h
          • lv_draw_sw_blend_to_argb8888_premultiplied.h
          • lv_draw_sw_blend_to_al88.h
          • lv_draw_sw_blend_private.h
          • lv_draw_sw_blend.h
          • neon
            • lv_blend_neon.h
          • helium
            • lv_blend_helium.h
          • arm2d
            • lv_blend_arm2d.h
        • arm2d
          • lv_draw_sw_helium.h
          • lv_draw_sw_arm2d.h
      • nxp
        • pxp
          • lv_pxp_cfg.h
          • lv_draw_pxp.h
          • lv_pxp_osa.h
          • lv_pxp_utils.h
        • g2d
          • lv_g2d_utils.h
          • lv_g2d_buf_map.h
          • lv_draw_g2d.h
        • vglite
          • lv_vglite_utils.h
          • lv_vglite_buf.h
          • lv_vglite_path.h
          • lv_draw_vglite.h
          • lv_vglite_matrix.h
      • nema_gfx
        • lv_draw_nema_gfx_utils.h
        • lv_draw_nema_gfx.h
        • lv_nema_gfx_path.h
    • indev
      • lv_indev_gesture_private.h
      • lv_indev_scroll.h
      • lv_indev_private.h
      • lv_indev_gesture.h
      • lv_indev.h
    • misc
      • lv_fs.h
      • lv_timer.h
      • lv_circle_buf.h
      • lv_math.h
      • lv_timer_private.h
      • lv_color.h
      • lv_bidi.h
      • lv_text_private.h
      • lv_event.h
      • lv_color_op_private.h
      • lv_text.h
      • lv_bidi_private.h
      • lv_matrix.h
      • lv_log.h
      • lv_tree.h
      • lv_profiler_builtin.h
      • lv_text_ap.h
      • lv_area.h
      • lv_lru.h
      • lv_anim_timeline.h
      • lv_anim.h
      • lv_fs_private.h
      • lv_rb.h
      • lv_async.h
      • lv_palette.h
      • lv_grad.h
      • lv_profiler_builtin_private.h
      • lv_area_private.h
      • lv_style_private.h
      • lv_profiler.h
      • lv_utils.h
      • lv_assert.h
      • lv_anim_private.h
      • lv_ll.h
      • lv_rb_private.h
      • lv_event_private.h
      • lv_style_gen.h
      • lv_style.h
      • lv_color_op.h
      • lv_array.h
      • lv_iter.h
      • lv_templ.h
      • cache
        • lv_cache.h
        • lv_cache_entry_private.h
        • lv_cache_private.h
        • lv_cache_entry.h
        • instance
          • lv_image_cache.h
          • lv_image_header_cache.h
          • lv_cache_instance.h
        • class
          • lv_cache_lru_ll.h
          • lv_cache_class.h
          • lv_cache_lru_rb.h
    • drivers
      • lv_drivers.h
      • evdev
        • lv_evdev_private.h
        • lv_evdev.h
      • libinput
        • lv_libinput_private.h
        • lv_xkb.h
        • lv_libinput.h
        • lv_xkb_private.h
      • display
        • ili9341
          • lv_ili9341.h
        • st7789
          • lv_st7789.h
        • tft_espi
          • lv_tft_espi.h
        • nxp_elcdif
          • lv_nxp_elcdif.h
        • lcd
          • lv_lcd_generic_mipi.h
        • st_ltdc
          • lv_st_ltdc.h
        • ft81x
          • lv_ft81x_defines.h
          • lv_ft81x.h
        • fb
          • lv_linux_fbdev.h
        • renesas_glcdc
          • lv_renesas_glcdc.h
        • st7735
          • lv_st7735.h
        • drm
          • lv_linux_drm.h
        • st7796
          • lv_st7796.h
      • wayland
        • lv_wl_touch.h
        • lv_wayland.h
        • lv_wl_keyboard.h
        • lv_wayland_private.h
        • lv_wl_pointer_axis.h
        • lv_wl_pointer.h
        • lv_wl_window.h
        • lv_wayland_smm.h
      • x11
        • lv_x11.h
      • sdl
        • lv_sdl_window.h
        • lv_sdl_mouse.h
        • lv_sdl_keyboard.h
        • lv_sdl_mousewheel.h
        • lv_sdl_private.h
      • windows
        • lv_windows_input_private.h
        • lv_windows_display.h
        • lv_windows_context.h
        • lv_windows_input.h
      • nuttx
        • lv_nuttx_touchscreen.h
        • lv_nuttx_entry.h
        • lv_nuttx_cache.h
        • lv_nuttx_lcd.h
        • lv_nuttx_fbdev.h
        • lv_nuttx_image_cache.h
        • lv_nuttx_libuv.h
        • lv_nuttx_profiler.h
      • glfw
        • lv_glfw_window_private.h
        • lv_glfw_window.h
        • lv_opengles_texture.h
        • lv_opengles_driver.h
        • lv_opengles_debug.h
      • uefi
        • lv_uefi_display.h
        • lv_uefi_edk2.h
        • lv_uefi_private.h
        • lv_uefi_gnu_efi.h
        • lv_uefi_indev.h
        • lv_uefi_std_wrapper.h
        • lv_uefi.h
        • lv_uefi_context.h
      • qnx
        • lv_qnx.h
    • tick
      • lv_tick_private.h
      • lv_tick.h
    • layouts
      • lv_layout_private.h
      • lv_layout.h
      • grid
        • lv_grid.h
      • flex
        • lv_flex.h
Back to top
View this page

Menu (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.

Parts and Styles¶

The Menu Widget is built from the following Widgets:

  • Main container: lv_menu_main_cont

  • Main header: lv_menu_main_header_cont

  • Back button: Button (lv_button)

  • Back button icon: Image (lv_image)

  • Main Page: lv_menu_page

  • Sidebar container: lv_menu_sidebar_cont

  • Sidebar header: lv_menu_sidebar_header_cont

  • Back button: Button (lv_button)

  • Back button icon: Image (lv_image)

  • Sidebar Page: lv_menu_page

Usage¶

Create a Menu¶

lv_menu_create(parent) creates a new empty Menu.

This creates a Menu Widget with this object hierarchy:

  • Menu: lv_menu_t
    • Hidden Sub-Page Storage: lv_obj_t

    • Main container: lv_menu_main_cont_class
      • Main header: lv_menu_main_header_cont_class
        • Back button: Button (lv_button)
          • Back button icon: Image (lv_image)

        • Main header title: Label (lv_label) (default hidden)

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

Header mode¶

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 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:

  • 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.

Events¶

  • 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.

  • LV_EVENT_CLICKED Sent when a back button 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.

    • lv_menu_back_button_is_root(menu, button) to check if button is root back button.

Further Reading

Learn more about Base-Widget Events emitted by all Widgets.

Learn more about Events.

Keys¶

No Keys are processed by Menu Widgets.

Further Reading

Learn more about Keys.

Example¶

Simple Menu¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_BUILD_EXAMPLES

void lv_example_menu_1(void)
{
    /*Create a menu object*/
    lv_obj_t * menu = lv_menu_create(lv_screen_active());
    lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));
    lv_obj_center(menu);

    lv_obj_t * cont;
    lv_obj_t * label;

    /*Create a sub page*/
    lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(sub_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here");

    /*Create a main page*/
    lv_obj_t * main_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 1");

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 2");

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 3 (Click me!)");
    lv_menu_set_load_page_event(menu, cont, sub_page);

    lv_menu_set_page(menu, main_page);
}

#endif

Simple Menu with root btn¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_USE_MSGBOX && LV_BUILD_EXAMPLES

static void back_event_handler(lv_event_t * e)
{
    lv_obj_t * obj = lv_event_get_target_obj(e);
    lv_obj_t * menu = (lv_obj_t *)lv_event_get_user_data(e);

    if(lv_menu_back_button_is_root(menu, obj)) {
        lv_obj_t * mbox1 = lv_msgbox_create(NULL);
        lv_msgbox_add_title(mbox1, "Hello");
        lv_msgbox_add_text(mbox1, "Root back btn click.");
        lv_msgbox_add_close_button(mbox1);
    }
}

void lv_example_menu_2(void)
{
    lv_obj_t * menu = lv_menu_create(lv_screen_active());
    lv_menu_set_mode_root_back_button(menu, LV_MENU_ROOT_BACK_BUTTON_ENABLED);
    lv_obj_add_event_cb(menu, back_event_handler, LV_EVENT_CLICKED, menu);
    lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));
    lv_obj_center(menu);

    lv_obj_t * cont;
    lv_obj_t * label;

    /*Create a sub page*/
    lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(sub_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here");

    /*Create a main page*/
    lv_obj_t * main_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 1");

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 2");

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 3 (Click me!)");
    lv_menu_set_load_page_event(menu, cont, sub_page);

    lv_menu_set_page(menu, main_page);
}

#endif

Simple Menu with custom header¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_BUILD_EXAMPLES

void lv_example_menu_3(void)
{
    /*Create a menu object*/
    lv_obj_t * menu = lv_menu_create(lv_screen_active());
    lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));
    lv_obj_center(menu);

    /*Modify the header*/
    lv_obj_t * back_btn = lv_menu_get_main_header_back_button(menu);
    lv_obj_t * back_button_label = lv_label_create(back_btn);
    lv_label_set_text(back_button_label, "Back");

    lv_obj_t * cont;
    lv_obj_t * label;

    /*Create sub pages*/
    lv_obj_t * sub_1_page = lv_menu_page_create(menu, "Page 1");

    cont = lv_menu_cont_create(sub_1_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here");

    lv_obj_t * sub_2_page = lv_menu_page_create(menu, "Page 2");

    cont = lv_menu_cont_create(sub_2_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here");

    lv_obj_t * sub_3_page = lv_menu_page_create(menu, "Page 3");

    cont = lv_menu_cont_create(sub_3_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding here");

    /*Create a main page*/
    lv_obj_t * main_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 1 (Click me!)");
    lv_menu_set_load_page_event(menu, cont, sub_1_page);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 2 (Click me!)");
    lv_menu_set_load_page_event(menu, cont, sub_2_page);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 3 (Click me!)");
    lv_menu_set_load_page_event(menu, cont, sub_3_page);

    lv_menu_set_page(menu, main_page);
}

#endif

Simple Menu with floating btn to add new menu page¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_BUILD_EXAMPLES

static uint32_t btn_cnt = 1;
static lv_obj_t * main_page;
static lv_obj_t * menu;

static void float_button_event_cb(lv_event_t * e)
{
    LV_UNUSED(e);

    btn_cnt++;

    lv_obj_t * cont;
    lv_obj_t * label;

    lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(sub_page);
    label = lv_label_create(cont);
    lv_label_set_text_fmt(label, "Hello, I am hiding inside %" LV_PRIu32"", btn_cnt);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text_fmt(label, "Item %" LV_PRIu32"", btn_cnt);
    lv_menu_set_load_page_event(menu, cont, sub_page);

    lv_obj_scroll_to_view_recursive(cont, LV_ANIM_ON);
}

void lv_example_menu_4(void)
{
    /*Create a menu object*/
    menu = lv_menu_create(lv_screen_active());
    lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));
    lv_obj_center(menu);

    lv_obj_t * cont;
    lv_obj_t * label;

    /*Create a sub page*/
    lv_obj_t * sub_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(sub_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Hello, I am hiding inside the first item");

    /*Create a main page*/
    main_page = lv_menu_page_create(menu, NULL);

    cont = lv_menu_cont_create(main_page);
    label = lv_label_create(cont);
    lv_label_set_text(label, "Item 1");
    lv_menu_set_load_page_event(menu, cont, sub_page);

    lv_menu_set_page(menu, main_page);

    /*Create floating btn*/
    lv_obj_t * float_btn = lv_button_create(lv_screen_active());
    lv_obj_set_size(float_btn, 50, 50);
    lv_obj_add_flag(float_btn, LV_OBJ_FLAG_FLOATING);
    lv_obj_align(float_btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10);
    lv_obj_add_event_cb(float_btn, float_button_event_cb, LV_EVENT_CLICKED, menu);
    lv_obj_set_style_radius(float_btn, LV_RADIUS_CIRCLE, 0);
    lv_obj_set_style_bg_image_src(float_btn, LV_SYMBOL_PLUS, 0);
    lv_obj_set_style_text_font(float_btn, lv_theme_get_font_large(float_btn), 0);
}

#endif

Complex Menu¶

C code  

 View on GitHub
#include "../../lv_examples.h"
#if LV_USE_MENU && LV_USE_MSGBOX && LV_BUILD_EXAMPLES

typedef enum {
    LV_MENU_ITEM_BUILDER_VARIANT_1,
    LV_MENU_ITEM_BUILDER_VARIANT_2
} lv_menu_builder_variant_t;

static void back_event_handler(lv_event_t * e);
static void switch_handler(lv_event_t * e);
static lv_obj_t * root_page;
static lv_obj_t * create_text(lv_obj_t * parent, const char * icon, const char * txt,
                              lv_menu_builder_variant_t builder_variant);
static lv_obj_t * create_slider(lv_obj_t * parent,
                                const char * icon, const char * txt, int32_t min, int32_t max, int32_t val);
static lv_obj_t * create_switch(lv_obj_t * parent,
                                const char * icon, const char * txt, bool chk);

void lv_example_menu_5(void)
{
    lv_obj_t * menu = lv_menu_create(lv_screen_active());

    lv_color_t bg_color = lv_obj_get_style_bg_color(menu, 0);
    if(lv_color_brightness(bg_color) > 127) {
        lv_obj_set_style_bg_color(menu, lv_color_darken(lv_obj_get_style_bg_color(menu, 0), 10), 0);
    }
    else {
        lv_obj_set_style_bg_color(menu, lv_color_darken(lv_obj_get_style_bg_color(menu, 0), 50), 0);
    }
    lv_menu_set_mode_root_back_button(menu, LV_MENU_ROOT_BACK_BUTTON_ENABLED);
    lv_obj_add_event_cb(menu, back_event_handler, LV_EVENT_CLICKED, menu);
    lv_obj_set_size(menu, lv_display_get_horizontal_resolution(NULL), lv_display_get_vertical_resolution(NULL));
    lv_obj_center(menu);

    lv_obj_t * cont;
    lv_obj_t * section;

    /*Create sub pages*/
    lv_obj_t * sub_mechanics_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_mechanics_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    lv_menu_separator_create(sub_mechanics_page);
    section = lv_menu_section_create(sub_mechanics_page);
    create_slider(section, LV_SYMBOL_SETTINGS, "Velocity", 0, 150, 120);
    create_slider(section, LV_SYMBOL_SETTINGS, "Acceleration", 0, 150, 50);
    create_slider(section, LV_SYMBOL_SETTINGS, "Weight limit", 0, 150, 80);

    lv_obj_t * sub_sound_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_sound_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    lv_menu_separator_create(sub_sound_page);
    section = lv_menu_section_create(sub_sound_page);
    create_switch(section, LV_SYMBOL_AUDIO, "Sound", false);

    lv_obj_t * sub_display_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_display_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    lv_menu_separator_create(sub_display_page);
    section = lv_menu_section_create(sub_display_page);
    create_slider(section, LV_SYMBOL_SETTINGS, "Brightness", 0, 150, 100);

    lv_obj_t * sub_software_info_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_software_info_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    section = lv_menu_section_create(sub_software_info_page);
    create_text(section, NULL, "Version 1.0", LV_MENU_ITEM_BUILDER_VARIANT_1);

    lv_obj_t * sub_legal_info_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_legal_info_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    section = lv_menu_section_create(sub_legal_info_page);
    for(uint32_t i = 0; i < 15; i++) {
        create_text(section, NULL,
                    "This is a long long long long long long long long long text, if it is long enough it may scroll.",
                    LV_MENU_ITEM_BUILDER_VARIANT_1);
    }

    lv_obj_t * sub_about_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_about_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    lv_menu_separator_create(sub_about_page);
    section = lv_menu_section_create(sub_about_page);
    cont = create_text(section, NULL, "Software information", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_software_info_page);
    cont = create_text(section, NULL, "Legal information", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_legal_info_page);

    lv_obj_t * sub_menu_mode_page = lv_menu_page_create(menu, NULL);
    lv_obj_set_style_pad_hor(sub_menu_mode_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    lv_menu_separator_create(sub_menu_mode_page);
    section = lv_menu_section_create(sub_menu_mode_page);
    cont = create_switch(section, LV_SYMBOL_AUDIO, "Sidebar enable", true);
    lv_obj_add_event_cb(lv_obj_get_child(cont, 2), switch_handler, LV_EVENT_VALUE_CHANGED, menu);

    /*Create a root page*/
    root_page = lv_menu_page_create(menu, "Settings");
    lv_obj_set_style_pad_hor(root_page, lv_obj_get_style_pad_left(lv_menu_get_main_header(menu), 0), 0);
    section = lv_menu_section_create(root_page);
    cont = create_text(section, LV_SYMBOL_SETTINGS, "Mechanics", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_mechanics_page);
    cont = create_text(section, LV_SYMBOL_AUDIO, "Sound", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_sound_page);
    cont = create_text(section, LV_SYMBOL_SETTINGS, "Display", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_display_page);

    create_text(root_page, NULL, "Others", LV_MENU_ITEM_BUILDER_VARIANT_1);
    section = lv_menu_section_create(root_page);
    cont = create_text(section, NULL, "About", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_about_page);
    cont = create_text(section, LV_SYMBOL_SETTINGS, "Menu mode", LV_MENU_ITEM_BUILDER_VARIANT_1);
    lv_menu_set_load_page_event(menu, cont, sub_menu_mode_page);

    lv_menu_set_sidebar_page(menu, root_page);

    lv_obj_send_event(lv_obj_get_child(lv_obj_get_child(lv_menu_get_cur_sidebar_page(menu), 0), 0), LV_EVENT_CLICKED,
                      NULL);
}

static void back_event_handler(lv_event_t * e)
{
    lv_obj_t * obj = lv_event_get_target_obj(e);
    lv_obj_t * menu = (lv_obj_t *)lv_event_get_user_data(e);

    if(lv_menu_back_button_is_root(menu, obj)) {
        lv_obj_t * mbox1 = lv_msgbox_create(NULL);
        lv_msgbox_add_title(mbox1, "Hello");
        lv_msgbox_add_text(mbox1, "Root back btn click.");
        lv_msgbox_add_close_button(mbox1);
    }
}

static void switch_handler(lv_event_t * e)
{
    lv_event_code_t code = lv_event_get_code(e);
    lv_obj_t * menu = (lv_obj_t *)lv_event_get_user_data(e);
    lv_obj_t * obj = lv_event_get_target_obj(e);
    if(code == LV_EVENT_VALUE_CHANGED) {
        if(lv_obj_has_state(obj, LV_STATE_CHECKED)) {
            lv_menu_set_page(menu, NULL);
            lv_menu_set_sidebar_page(menu, root_page);
            lv_obj_send_event(lv_obj_get_child(lv_obj_get_child(lv_menu_get_cur_sidebar_page(menu), 0), 0), LV_EVENT_CLICKED,
                              NULL);
        }
        else {
            lv_menu_set_sidebar_page(menu, NULL);
            lv_menu_clear_history(menu); /* Clear history because we will be showing the root page later */
            lv_menu_set_page(menu, root_page);
        }
    }
}

static lv_obj_t * create_text(lv_obj_t * parent, const char * icon, const char * txt,
                              lv_menu_builder_variant_t builder_variant)
{
    lv_obj_t * obj = lv_menu_cont_create(parent);

    lv_obj_t * img = NULL;
    lv_obj_t * label = NULL;

    if(icon) {
        img = lv_image_create(obj);
        lv_image_set_src(img, icon);
    }

    if(txt) {
        label = lv_label_create(obj);
        lv_label_set_text(label, txt);
        lv_label_set_long_mode(label, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR);
        lv_obj_set_flex_grow(label, 1);
    }

    if(builder_variant == LV_MENU_ITEM_BUILDER_VARIANT_2 && icon && txt) {
        lv_obj_add_flag(img, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
        lv_obj_swap(img, label);
    }

    return obj;
}

static lv_obj_t * create_slider(lv_obj_t * parent, const char * icon, const char * txt, int32_t min, int32_t max,
                                int32_t val)
{
    lv_obj_t * obj = create_text(parent, icon, txt, LV_MENU_ITEM_BUILDER_VARIANT_2);

    lv_obj_t * slider = lv_slider_create(obj);
    lv_obj_set_flex_grow(slider, 1);
    lv_slider_set_range(slider, min, max);
    lv_slider_set_value(slider, val, LV_ANIM_OFF);

    if(icon == NULL) {
        lv_obj_add_flag(slider, LV_OBJ_FLAG_FLEX_IN_NEW_TRACK);
    }

    return obj;
}

static lv_obj_t * create_switch(lv_obj_t * parent, const char * icon, const char * txt, bool chk)
{
    lv_obj_t * obj = create_text(parent, icon, txt, LV_MENU_ITEM_BUILDER_VARIANT_1);

    lv_obj_t * sw = lv_switch_create(obj);
    lv_obj_add_state(sw, chk ? LV_STATE_CHECKED : 0);

    return obj;
}

#endif

API¶

lv_menu.h

lv_menu_private.h

Next
Message Box (lv_msgbox)
Previous
Lottie (lv_lottie)
Copyright © 2021-2025, LVGL Kft
Made with Furo
Last updated on Jun 11, 2025
On this page
  • Menu (lv_menu)
    • Overview
    • Parts and Styles
    • Usage
      • Create a Menu
      • Header mode
      • Root back button mode
      • Create a Menu Page
      • Set a Menu Page in the main area
      • Set a Menu Page in the sidebar
      • Linking between Menu Pages
      • Create a Menu container, section, separator
    • Events
    • Keys
    • Example
      • Simple Menu
      • Simple Menu with root btn
      • Simple Menu with custom header
      • Simple Menu with floating btn to add new menu page
      • Complex Menu
    • API