A menu bar holding a sequence of menus.
A menu bar can have up to one open menu at a time.
:: a typeCtrl KGHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11
Modulebrick-3.0Haskell2010
This module provides a menu bar for grouping menus together.
Menu bars carry menus of a particular type using the menu types
provided in the Brick.Widgets.Menu module. The type aliases
provided here correspond to the aliases for menu use cases:
SimpleMenuBar: a menu bar made up of SimpleMenus created with simpleMenu
DispatchingMenuBar: a menu bar made up of DispatchingMenus created with menuWithDispatcher
MenuBar: the fully general type for menu bars with menus created with menu
In all cases, use newMenuBar to construct a menu bar, and create its menus using the corresponding menu constructor for the type of menu bar you want to use.
Render the menu bar with renderMenuBar and handle menu bar events with handleMenuBarEvent, deferring to the application's event handling for events that the menu bar doesn't handle.
Similar to individual menus, menu bars have an orientation that can be changed with setMenuBarOrientation.
This API requires the use of lenses for application state fields that store menu bar state.
See the MenuBarDemo demonstration program for a complete working
example of using this API.
To use this module in an application:
Choose a menu bar type that you want to work with such as SimpleMenuBar.
Add an application state field and lens for a value of the menu bar's type, and add a constructor to the application's resource name type, with an argument of type MenuRegion, for each menu in the menu bar. Add lenses to the application state type with makeLenses.
Populate the application's initial state with the menu bar.
Render the menu bar with renderMenuBar.
Handle incoming events first with handleMenuBarEvent, and when
handleMenuBarEvent returns False, pass unhandled events on to
the existing application event handler.
A menu bar holding a sequence of menus.
A menu bar can have up to one open menu at a time.
A specialization of MenuBar for menus with EventM handlers; use this with simpleMenu.
A specialization of MenuBar for menus with abstract key event triggers; this with menuWithDispatcher.
Create a new menu bar from the specified menu list. If the list is empty, this calls error.
handleMenuBarEvent Handle an event for this menu bar and return True, or return
False if the event was not handled (e.g. because the event was not
a menu title mouse click or because no menu was open to receive the
event).
Events handled include:
Mouse clicks on menu titles will open the clicked menu, closing other open menus.
Left and Right arrow keys will cycle between menus if there is an open menu.
If a submenu entry is selected, the arrow keys will open it or close it if it is open, depending on the configured menu bar orientation.
Esc will close the currently-open menu.
In all other cases, this will attempt to defer to the opened menu to
handle the event. This returns True if the event was one of the
above and was handled, True if the event was not one of the above
but was handled by the open menu, or False otherwise.
A return value of True indicates that the event should not be
handled by the application because it was destined for the menu bar
or one of its menus; a return value of False indicates that the
event should be handled by the application because it did not affect
the menu bar or its menus in their current state for any reason.
Consequently, a common pattern when using this function will look
something like this:
myApplicationEventHandler :: BrickEvent n e -> EventM n s ()
myApplicationEventHandler e = do
handled <- handleMenuBarEvent myMenuBarLens e
when (not handled) $ do
-- Go on to handle the event in the rest of the application
Render this menu bar with the given application state as input.
Return whether this menu bar has an open menu.
Close all open menus in this menu bar.
Open the menu at the specified index, closing any other open menus in the menu bar. If the index is invalid, this does nothing.
Toggle the open state of the menu at the specified index. If toggling to open, this will close any other open menus in the menu bar. If the index is invalid, this does nothing.
Set the menu orientation of the menu bar and all of its menus. For details, see setMenuOrientation.