Menu Bars
BeginMenuBar
ImGuiWindowFlags_MenuBar flag set on parent window).
bool
True if menu bar is open. Only call EndMenuBar() if this returns true.
EndMenuBar
EndMenuBar() if BeginMenuBar() returns true.
BeginMainMenuBar
bool
True if menu bar is open. Only call EndMainMenuBar() if this returns true.
EndMainMenuBar
EndMainMenuBar() if BeginMainMenuBar() returns true.
Menus
BeginMenu
EndMenu() if this returns true.
const char*
Menu label
bool
default:"true"
Whether the menu is enabled (grayed out if false)
bool
True when menu is open
EndMenu
EndMenu() if BeginMenu() returns true.
Menu Items
MenuItem
const char*
Menu item label
const char*
default:"NULL"
Keyboard shortcut text (display only, not processed by ImGui)
bool
default:"false"
Whether the item is selected (displays checkmark)
bool
default:"true"
Whether the item is enabled
bool
True when activated
MenuItem (pointer)
*p_selected if p_selected != NULL.
const char*
Menu item label
const char*
Keyboard shortcut text
bool*
Pointer to selection state (automatically toggled)
bool
default:"true"
Whether the item is enabled
bool
True when activated
Complete Example
Notes
- MenuItem keyboard shortcuts are displayed but NOT processed by Dear ImGui. You need to handle keyboard input yourself.
- You can use
##in labels to hide text after it (useful for creating unique IDs). - Menus can be nested to any depth.
- Use
ImGui::Separator()to add horizontal lines between menu items. - MenuItem returns true on activation, which happens on mouse release (not press).