HORIZON HASKELLDocslts/ghc-10.0.x8174fa42026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8174fa4 · 2026-10-11

Modulebrick-3.0Haskell2010

Brick.Widgets.MenuBar

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:

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.

Adding a Menu Bar to An Application

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.

  • 3 types
  • 8 values
  • Packagebrick-3.0
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMenuBar.hs

Types

3 declarations
datadata MenuBar s n k
#

A menu bar holding a sequence of menus.

A menu bar can have up to one open menu at a time.

Creating menu bars

1 declaration
valuenewMenuBar :: [Menu s n k] -> MenuBar s n k
#

Create a new menu bar from the specified menu list. If the list is empty, this calls error.

Handling events

1 declaration
valuehandleMenuBarEvent
  1. :: Eq n
  2. => Lens' s (MenuBar s n k)

    The lens into the application state where the menu state can be found

  3. -> BrickEvent n e

    The event to handle

  4. -> EventM n s Bool
#

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

Rendering

1 declaration

Working with menu bars

5 declarations
valueopenMenuAtIndex :: Int -> MenuBar s n k -> MenuBar s n k
#

Open the menu at the specified index, closing any other open menus in the menu bar. If the index is invalid, this does nothing.

valuetoggleMenuAtIndex :: Int -> MenuBar s n k -> MenuBar s n k
#

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.