brick 3.0 → 3.1
raw patch · 14 files changed
+229/−101 lines, 14 files
Files
- CHANGELOG.md +40/−0
- brick.cabal +2/−9
- docs/guide.rst +5/−15
- programs/AnimationDemo.hs +3/−9
- programs/FormDemo.hs +3/−10
- programs/MenuBarDemo.hs +27/−14
- programs/MenuDemo.hs +1/−4
- programs/MenuKeybindingsDemo.hs +1/−4
- programs/MouseDemo.hs +1/−4
- programs/ViewportScrollbarsDemo.hs +2/−9
- src/Brick/Main.hs +44/−10
- src/Brick/Types/Internal.hs +4/−0
- src/Brick/Widgets/Menu.hs +58/−10
- src/Brick/Widgets/MenuBar.hs +38/−3
CHANGELOG.md view
@@ -2,6 +2,46 @@ Brick changelog --------------- +3.1+---++API changes:++* `Brick.Main.customMain` now takes only a single optional Vty handle+ builder rather than two separate arguments for the initial handle and+ subsequent rebuiding. Prior to this change, `customMain` effectively+ always took the same thing for its first two arguments: a Vty handle+ builder, and a handle built with that same builder. That had two+ negative consequences: first, the duplication of the builder when+ the library could have handled the initial Vty handle creation, and+ second, the fact that callers of `customMain` had to provide these+ two arguments even in cases where the only reason to call customMain+ was to provide a custom event channel. This change addresses these+ problems by combining the Vty handle arguments so that the caller only+ passes the builder (and the library invokes it to create an initial+ handle) and the builder is now optional for cases where the caller+ doesn't care or just wants the default Vty behavior.+* `Brick.Main`: added convenience functions `enableMouseEvents` and+ `disableMouseEvents` to make it easier to manage mouse mode without+ needing to use `customMain` to get access to the Vty handle.+* `Brick.Widgets.MenuBar`: added `openNamedMenu` and `toggleNamedMenu`.+* `newMenuBar` now raises an exception if any menus in the menu bar use+ duplicate resource name constructors.++Behavior improvements:++* `handleMenuEvent` now handles mouse click events on parent menus even+ when submenus are open. Prior to this change, a menu with an open+ submenu would ignore mouse clicks in the body of the parent menu.+* `handleMenuEvent` now handles mouse clicks so that when they fall+ outside known regions, the entire menu is closed, not just the most+ recently-opened submenu.++Other improvements:++* Improved the documentation for the `Viewport` and `ViewportScroll`+ types to make their use cases a bit clearer.+ 3.0 ---
brick.cabal view
@@ -1,5 +1,5 @@ name: brick-version: 3.0+version: 3.1 synopsis: A declarative terminal user interface library description: Write terminal user interfaces (TUIs) painlessly with 'brick'! You@@ -216,7 +216,6 @@ text, microlens, microlens-th,- vty-crossplatform, vty executable brick-text-wrap-demo@@ -269,7 +268,6 @@ build-depends: base, brick, vty,- vty-crossplatform, microlens-mtl, microlens-th @@ -308,8 +306,7 @@ vty, microlens >= 0.3.0.0, microlens-th,- microlens-mtl,- mtl+ microlens-mtl executable brick-layer-demo if !flag(demos)@@ -438,7 +435,6 @@ build-depends: base, brick, vty,- vty-crossplatform, containers, microlens-platform @@ -553,7 +549,6 @@ build-depends: base, brick, vty,- mtl, text, microlens, microlens-mtl,@@ -570,7 +565,6 @@ build-depends: base, brick, vty,- mtl, text, microlens, microlens-mtl,@@ -587,7 +581,6 @@ build-depends: base, brick, vty,- mtl, text, microlens, microlens-mtl,
docs/guide.rst view
@@ -411,9 +411,7 @@ main = do eventChan <- Brick.BChan.newBChan 10 let buildVty = Graphics.Vty.CrossPlatform.mkVty Graphics.Vty.Config.defaultConfig- initialVty <- buildVty- finalState <- customMain initialVty buildVty- (Just eventChan) app initialState+ finalState <- customMain (Just buildVty) (Just eventChan) app initialState -- Use finalState and exit The ``customMain`` function lets us have control over how the ``vty``@@ -1086,18 +1084,10 @@ Mouse Support ============= -Some terminal emulators support mouse interaction. The Vty library used-by brick provides these low-level events if mouse mode has been enabled.-To enable mouse mode, we need to get access to the Vty library handle in-``EventM``:--.. code:: haskell-- do- vty <- Brick.Main.getVtyHandle- let output = outputIface vty- when (supportsMode output Mouse) $- liftIO $ setMode output Mouse True+Some terminal emulators support mouse interaction. The Vty library+used by brick provides these low-level events if mouse mode has been+enabled. To enable mouse mode, call ``Brick.Main.enableMouseEvents`` in+``EventM``. Bear in mind that some terminals do not support mouse interaction, so use Vty's ``getModeStatus`` to find out whether your terminal will
programs/AnimationDemo.hs view
@@ -11,11 +11,10 @@ #endif import qualified Data.Map as M import qualified Graphics.Vty as V-import Graphics.Vty.CrossPlatform (mkVty) import Brick.BChan import Brick.Util (fg)-import Brick.Main (App(..), neverShowCursor, customMain, halt)+import Brick.Main (App(..), neverShowCursor, customMain, halt, enableMouseEvents) import Brick.AttrMap (AttrName, AttrMap, attrMap, attrName) import Brick.Types (Widget, EventM, BrickEvent(..), Location(..)) import Brick.Widgets.Border (border)@@ -198,7 +197,7 @@ App { appDraw = drawUI , appChooseCursor = neverShowCursor , appHandleEvent = appEvent- , appStartEvent = return ()+ , appStartEvent = enableMouseEvents , appAttrMap = const attrs } @@ -214,10 +213,5 @@ , _animation3 = Nothing , _clickAnimations = mempty }- buildVty = do- v <- mkVty V.defaultConfig- V.setMode (V.outputIface v) V.Mouse True- return v - initialVty <- buildVty- void $ customMain initialVty buildVty (Just chan) theApp initialState+ void $ customMain Nothing (Just chan) theApp initialState
programs/FormDemo.hs view
@@ -11,7 +11,6 @@ #endif import qualified Graphics.Vty as V-import Graphics.Vty.CrossPlatform (mkVty) import Brick import Brick.Forms@@ -131,18 +130,13 @@ modify $ setFieldValid (st^.age >= 18) AgeField , appChooseCursor = focusRingCursor formFocus- , appStartEvent = return ()+ , appStartEvent = enableMouseEvents , appAttrMap = const theMap } main :: IO () main = do- let buildVty = do- v <- mkVty V.defaultConfig- V.setMode (V.outputIface v) V.Mouse True- return v-- initialUserInfo = UserInfo { _name = ""+ let initialUserInfo = UserInfo { _name = "" , _address = "" , _age = 0 , _handed = RightHanded@@ -152,8 +146,7 @@ f = setFieldValid False AgeField $ mkForm initialUserInfo - initialVty <- buildVty- f' <- customMain initialVty buildVty Nothing app f+ f' <- defaultMain app f putStrLn "The starting form state was:" print initialUserInfo
programs/MenuBarDemo.hs view
@@ -7,7 +7,6 @@ import Lens.Micro.TH (makeLenses) import Lens.Micro.Mtl ((%=), use) import Control.Monad (void, when)-import Control.Monad.Trans (liftIO) #if !(MIN_VERSION_base(4,11,0)) import Data.Monoid ((<>)) #endif@@ -27,6 +26,7 @@ data Name = FileMenu MenuRegion | EditMenu MenuRegion | HelpMenu MenuRegion+ | FormatMenu MenuRegion deriving (Show, Ord, Eq) data St =@@ -69,22 +69,25 @@ -- Esc quits the application M.halt handleNonMenuBarEvent (T.VtyEvent (V.EvKey (V.KChar 'f') [V.MMeta])) =- menuBar %= toggleMenuAtIndex 0+ menuBar %= toggleNamedMenu FileMenu handleNonMenuBarEvent (T.VtyEvent (V.EvKey (V.KChar 'e') [V.MMeta])) =- menuBar %= toggleMenuAtIndex 1+ menuBar %= toggleNamedMenu EditMenu handleNonMenuBarEvent (T.VtyEvent (V.EvKey (V.KChar 'h') [V.MMeta])) =- menuBar %= toggleMenuAtIndex 2-handleNonMenuBarEvent (T.VtyEvent (V.EvKey (V.KChar 'o') [])) = do- menuBarOrientation %= nextOrientation- o <- use menuBarOrientation- menuBar %= setMenuBarOrientation o+ menuBar %= toggleNamedMenu HelpMenu+handleNonMenuBarEvent (T.VtyEvent (V.EvKey (V.KChar 'o') [])) =+ toggleMenuBarOrientation handleNonMenuBarEvent _ = return () -nextOrientation :: MenuOrientation -> MenuOrientation-nextOrientation LeftToRight = RightToLeft-nextOrientation RightToLeft = LeftToRight+toggleMenuBarOrientation :: T.EventM Name St ()+toggleMenuBarOrientation = do+ let nextOrientation LeftToRight = RightToLeft+ nextOrientation RightToLeft = LeftToRight + menuBarOrientation %= nextOrientation+ o <- use menuBarOrientation+ menuBar %= setMenuBarOrientation o+ aMap :: AttrMap aMap = attrMap V.defAttr [ (menuAttr, fg V.white)@@ -99,9 +102,7 @@ app :: M.App St e Name app = M.App { M.appDraw = drawUi- , M.appStartEvent = do- vty <- M.getVtyHandle- liftIO $ V.setMode (V.outputIface vty) V.Mouse True+ , M.appStartEvent = M.enableMouseEvents , M.appHandleEvent = appEvent , M.appAttrMap = const aMap , M.appChooseCursor = M.showFirstCursor@@ -124,9 +125,21 @@ [ menuEntry "Undo" (return ()) , menuEntry "Redo" (return ()) , menuSeparator+ , submenu newFormatMenu+ , menuSeparator , menuEntry "Cut" (return ()) , menuEntry "Copy" (return ()) , menuEntry "Paste" (return ())+ ]++newFormatMenu :: SimpleMenu St Name+newFormatMenu =+ simpleMenu "Format" FormatMenu+ [ menuEntry "Bold" (return ())+ , menuEntry "Strikethrough" (return ())+ , menuEntry "Underline" (return ())+ , menuSeparator+ , menuEntry "Clear formatting" (return ()) ] newHelpMenu :: SimpleMenu St Name
programs/MenuDemo.hs view
@@ -7,7 +7,6 @@ import Lens.Micro.TH (makeLenses) import Lens.Micro.Mtl import Control.Monad (void, when)-import Control.Monad.Trans (liftIO) #if !(MIN_VERSION_base(4,11,0)) import Data.Monoid ((<>)) #endif@@ -101,9 +100,7 @@ app :: M.App St e Name app = M.App { M.appDraw = drawUi- , M.appStartEvent = do- vty <- M.getVtyHandle- liftIO $ V.setMode (V.outputIface vty) V.Mouse True+ , M.appStartEvent = M.enableMouseEvents , M.appHandleEvent = appEvent , M.appAttrMap = const aMap , M.appChooseCursor = M.showFirstCursor
programs/MenuKeybindingsDemo.hs view
@@ -7,7 +7,6 @@ import Lens.Micro.TH (makeLenses) import Lens.Micro.Mtl import Control.Monad (void, forM_)-import Control.Monad.Trans (liftIO) #if !(MIN_VERSION_base(4,11,0)) import Data.Monoid ((<>)) #endif@@ -127,9 +126,7 @@ app :: M.App St e Name app = M.App { M.appDraw = drawUi- , M.appStartEvent = do- vty <- M.getVtyHandle- liftIO $ V.setMode (V.outputIface vty) V.Mouse True+ , M.appStartEvent = M.enableMouseEvents , M.appHandleEvent = appEvent , M.appAttrMap = const aMap , M.appChooseCursor = M.showFirstCursor
programs/MouseDemo.hs view
@@ -6,7 +6,6 @@ import Lens.Micro.TH (makeLenses) import Lens.Micro.Mtl import Control.Monad (void)-import Control.Monad.Trans (liftIO) #if !(MIN_VERSION_base(4,11,0)) import Data.Monoid ((<>)) #endif@@ -117,9 +116,7 @@ app :: M.App St e Name app = M.App { M.appDraw = drawUi- , M.appStartEvent = do- vty <- M.getVtyHandle- liftIO $ V.setMode (V.outputIface vty) V.Mouse True+ , M.appStartEvent = M.enableMouseEvents , M.appHandleEvent = appEvent , M.appAttrMap = const aMap , M.appChooseCursor = M.showFirstCursor
programs/ViewportScrollbarsDemo.hs view
@@ -10,7 +10,6 @@ import Data.Monoid ((<>)) #endif import qualified Graphics.Vty as V-import Graphics.Vty.CrossPlatform (mkVty) import qualified Brick.Types as T import qualified Brick.Main as M@@ -192,7 +191,7 @@ app :: M.App St e Name app = M.App { M.appDraw = drawUi- , M.appStartEvent = return ()+ , M.appStartEvent = M.enableMouseEvents , M.appHandleEvent = appEvent , M.appAttrMap = const theme , M.appChooseCursor = M.neverShowCursor@@ -200,10 +199,4 @@ main :: IO () main = do- let buildVty = do- v <- mkVty V.defaultConfig- V.setMode (V.outputIface v) V.Mouse True- return v-- initialVty <- buildVty- void $ M.customMain initialVty buildVty Nothing app (St Nothing)+ void $ M.defaultMain app (St Nothing)
src/Brick/Main.hs view
@@ -45,6 +45,10 @@ , invalidateCacheEntry , invalidateCache + -- * Terminal mode conveniences+ , enableMouseEvents+ , disableMouseEvents+ -- * Renderer internals (for benchmarking) , renderFinal , getRenderState@@ -61,7 +65,7 @@ import Control.Concurrent (forkIO, killThread) import qualified Data.Foldable as F import Data.List (find)-import Data.Maybe (listToMaybe)+import Data.Maybe (listToMaybe, fromMaybe) import qualified Data.Map as M import qualified Data.Set as S import Graphics.Vty@@ -69,6 +73,7 @@ , Picture(..) , Cursor(..) , Event(..)+ , Mode(..) , update , outputIface , displayBounds@@ -76,6 +81,8 @@ , nextEvent , restoreInputState , inputIface+ , setMode+ , outputIface ) import Graphics.Vty.CrossPlatform (mkVty) import Graphics.Vty.Config (defaultConfig)@@ -209,13 +216,12 @@ -- prior to the first Vty initialization is the terminal input state -- that is restored on shutdown (regardless of exceptions). customMain :: (Ord n)- => Vty- -- ^ The initial Vty handle to use.- -> IO Vty- -- ^ An IO action to build a Vty handle. This is used- -- to build a Vty handle whenever the event loop needs- -- to reinitialize the terminal, e.g. on resume after- -- suspension.+ => Maybe (IO Vty)+ -- ^ An IO action to build a Vty handle. This is used to+ -- build a Vty handle at startup and whenever the event+ -- loop needs to reinitialize the terminal, e.g. on resume+ -- after suspension. If not given, the default Vty handle+ -- configuration will be used. -> Maybe (BChan e) -- ^ An event channel for sending custom events to the event -- loop (you write to this channel, the event loop reads from@@ -226,10 +232,13 @@ -> s -- ^ The initial application state. -> IO s-customMain initialVty buildVty mUserChan app initialAppState = do+customMain mBuildVty mUserChan app initialAppState = do+ let builder = fromMaybe (mkVty defaultConfig) mBuildVty+ initialVty <- builder+ let restoreInitialState = restoreInputState $ inputIface initialVty - (s, vty) <- customMainWithVty initialVty buildVty mUserChan app initialAppState+ (s, vty) <- customMainWithVty initialVty builder mUserChan app initialAppState `E.catch` (\(e::E.SomeException) -> restoreInitialState >> E.throw e) shutdown vty@@ -585,6 +594,10 @@ -- | A viewport scrolling handle for managing the scroll state of -- viewports.+--+-- Note that if you are wanting to obtain the current state of a+-- viewport rather than manipulate it, see 'lookupViewport' and its+-- associated result type, 'Viewport'. data ViewportScroll n = ViewportScroll { viewportName :: n -- ^ The name of the viewport to be controlled by@@ -695,3 +708,24 @@ makeVisible :: (Ord n) => n -> EventM n s () makeVisible n = EventM $ do lift $ lift $ modify (\s -> s { requestedVisibleNames = S.insert n $ requestedVisibleNames s })++-- | Enable terminal mouse events.+--+-- This is a convenience function provided as more direct alternative to+-- using 'getVtyHandle' and 'setMode'.+enableMouseEvents :: EventM n s ()+enableMouseEvents = setVtyMode Mouse True++-- | Disable terminal mouse events.+--+-- This is a convenience function provided as more direct alternative to+-- using 'getVtyHandle' and 'setMode'.+disableMouseEvents :: EventM n s ()+disableMouseEvents = setVtyMode Mouse False++-- | Set the given Vty mode status on the event handler's current Vty+-- handle.+setVtyMode :: Mode -> Bool -> EventM n s ()+setVtyMode m val = do+ vty <- getVtyHandle+ liftIO $ setMode (outputIface vty) m val
src/Brick/Types/Internal.hs view
@@ -248,6 +248,10 @@ -- | Describes the state of a viewport as it appears as its most recent -- rendering.+--+-- Note that if you are wanting to manipulate a viewport from within+-- 'Brick.Types.EventM', see 'Brick.Main.viewportScroll' and the+-- 'Brick.Main.ViewportScroll' type. data Viewport = VP { _vpLeft :: !Int -- ^ The column offset of left side of the viewport.
src/Brick/Widgets/Menu.hs view
@@ -486,9 +486,12 @@ handler trigger = case trigger of- TriggerEvent (ByKey b) -> invokeHandler $ lookupVtyEvent (kbKey b) (F.toList $ kbMods b) kd- TriggerEvent (ByEvent ev) -> invokeHandler $ lookupEvent ev kd- TriggerAction act -> act+ TriggerEvent (ByKey b) ->+ invokeHandler $ lookupVtyEvent (kbKey b) (F.toList $ kbMods b) kd+ TriggerEvent (ByEvent ev) ->+ invokeHandler $ lookupEvent ev kd+ TriggerAction act ->+ act where invokeHandler Nothing = return () invokeHandler (Just kh) = handlerAction $ kehHandler $ khHandler kh@@ -898,7 +901,11 @@ then return True else handleMenuEventFallback which path e -handleMenuEventFallback :: (Eq n) => Traversal' s (Menu s n k) -> [Int] -> BrickEvent n e -> EventM n s Bool+handleMenuEventFallback :: (Eq n)+ => Traversal' s (Menu s n k)+ -> [Int]+ -> BrickEvent n e+ -> EventM n s Bool handleMenuEventFallback which path (VtyEvent (Vty.EvKey k mods)) = withMenu (targetMenu which path) $ \m -> do handled <- menuFallbackEventHandler m k mods@@ -906,7 +913,11 @@ handleMenuEventFallback _ _ _ = return False -handleMenuEventCommon :: (Eq n) => Traversal' s (Menu s n k) -> [Int] -> BrickEvent n e -> EventM n s Bool+handleMenuEventCommon :: (Eq n)+ => Traversal' s (Menu s n k)+ -> [Int]+ -> BrickEvent n e+ -> EventM n s Bool handleMenuEventCommon which path (VtyEvent (Vty.EvKey Vty.KEnter [])) = do withMenu (targetMenu which path) $ \m -> do let sel = m^.menuSelectedIndexL@@ -933,12 +944,12 @@ handleMenuEventCommon which path (VtyEvent (Vty.EvKey Vty.KUp [])) = do targetMenu which path %= selectPrevEntry return True-handleMenuEventCommon which path (MouseDown n _ _ (Location (_, row))) = do- withMenu (targetMenu which path) $ \m -> do+handleMenuEventCommon which fullPath (MouseDown n _ _ (Location (_, row))) = do+ withMatchingMenu n which fullPath $ \path m -> do let mkRegionName = m^.menuRegionNameBuilderL if | mkRegionName MenuTitle == n -> do- (targetMenu which path).menuIsOpenL %= not+ targetMenu which path %= toggleMenu return True | mkRegionName MenuBody == n -> -- Map the location to the clicked menu entry; since each@@ -946,8 +957,10 @@ -- index here is equivalent to the item index. activateMenuItem which path row | otherwise -> return False-handleMenuEventCommon which path (VtyEvent (Vty.EvMouseDown {})) = do- targetMenu which path %= closeMenu+handleMenuEventCommon which _ (VtyEvent (Vty.EvMouseDown {})) = do+ -- A mouse click outside any known region means we should close the+ -- entire menu, including any open submenu chain.+ targetMenu which [] %= closeMenu return True handleMenuEventCommon which path (VtyEvent (Vty.EvKey Vty.KEsc [])) = do withMenu (targetMenu which path) $ \m -> do@@ -958,6 +971,41 @@ else return False handleMenuEventCommon _ _ _ = return False++-- | Given a resource name and a menu path, find the menu in the path+-- whose body or title matches the resource name, starting with the+-- menu referred to by the full given path. If one is found, invoke+-- the specified function on the located menu, including the path to+-- that menu. If the given path does not match the name, recurse to+-- the menu's parent and so on until the base menu is reached. If no+-- matching menu is found, return @False@.+withMatchingMenu :: (Eq n)+ => n+ -- ^ The name of the menu title or body to match+ -> Traversal' s (Menu s n k)+ -- ^ The base menu+ -> [Int]+ -- ^ The full menu path to match against+ -> ([Int] -> Menu s n k -> EventM n s Bool)+ -- ^ The function to invoke on the match, if found+ -> EventM n s Bool+withMatchingMenu n which path f = do+ mMenu <- preuse (targetMenu which path)+ case mMenu of+ Just m ->+ if menuMatchesName n m+ then f path m+ else case path of+ [] -> return False+ _ -> withMatchingMenu n which (init path) f+ Nothing -> return False++-- | Return whether the given resource name is the title name or body+-- name of the given menu.+menuMatchesName :: (Eq n) => n -> Menu s n k -> Bool+menuMatchesName n m =+ menuTitleName m == n ||+ menuRegionNameBuilder m MenuBody == n maybeCloseSubmenu :: Traversal' s (Menu s n k) -> [Int] -> EventM n s Bool maybeCloseSubmenu which path = do
src/Brick/Widgets/MenuBar.hs view
@@ -68,11 +68,14 @@ , closeAllMenus , openMenuAtIndex , toggleMenuAtIndex+ , toggleNamedMenu+ , openNamedMenu , setMenuBarOrientation ) where import Control.Monad (when)+import qualified Data.Set as S import Data.Maybe (isJust, listToMaybe, fromMaybe) import Lens.Micro.Platform ((^.), (&), (%~), (.~), Lens', ix, each) import Lens.Micro.Mtl@@ -105,10 +108,17 @@ type DispatchingMenuBar s n k = MenuBar s n (EventM n s (EntryTrigger s n k)) -- | Create a new menu bar from the specified menu list. If the list is--- empty, this calls 'error'.-newMenuBar :: [Menu s n k] -> MenuBar s n k+-- empty, this calls 'error'. If the list contains menus with the same+-- resource name constructor, this calls 'error'.+newMenuBar :: (Ord n) => [Menu s n k] -> MenuBar s n k newMenuBar [] = error "BUG: newMenuBar requires a non-empty list"-newMenuBar ms = MenuBar LeftToRight $ V.fromList ms+newMenuBar ms = MenuBar LeftToRight $ V.fromList uniqueMenus+ where+ uniqueMenus = if S.size menuNames == length ms+ then ms+ else error "newMenuBar: all menus must use unique resource name constructors"+ menuNames = S.fromList $+ menuTitleName <$> ms -- | Return whether this menu bar has an open menu. hasOpenMenu :: MenuBar s n k -> Bool@@ -252,6 +262,20 @@ openMenuAtIndex :: Int -> MenuBar s n k -> MenuBar s n k openMenuAtIndex i mb = (closeAllMenus mb) & menuBarMenusL.ix i %~ openMenu +-- | Open the menu with the specified resource name constructor, closing+-- any other open menus in the menu bar. If the index is invalid, this+-- does nothing.+openNamedMenu :: (Eq n) => (MenuRegion -> n) -> MenuBar s n k -> MenuBar s n k+openNamedMenu f mb =+ case findNamedMenu f mb of+ Just (i, _) -> (closeAllMenus mb) & menuBarMenusL.ix i %~ openMenu+ Nothing -> mb++findNamedMenu :: (Eq n) => (MenuRegion -> n) -> MenuBar s n k -> Maybe (Int, Menu s n k)+findNamedMenu f mb =+ V.find ((== (f MenuTitle)) . menuTitleName . snd) $+ V.zip (V.fromList [0..]) $ menuBarMenus mb+ -- | Set the menu orientation of the menu bar and all of its menus. For -- details, see 'setMenuOrientation'. setMenuBarOrientation :: MenuOrientation -> MenuBar s n k -> MenuBar s n k@@ -268,6 +292,17 @@ Just (idx, _) -> if idx == i then closeAllMenus mb else openMenuAtIndex i mb++-- | Toggle the open state of the menu with the specified resource name+-- constructor. If toggling to open, this will close any other open+-- menus in the menu bar. If the index is invalid, this does nothing.+toggleNamedMenu :: (Eq n) => (MenuRegion -> n) -> MenuBar s n k -> MenuBar s n k+toggleNamedMenu f mb =+ case getOpenMenu mb of+ Nothing -> openNamedMenu f mb+ Just (_, m) -> if menuTitleName m == f MenuTitle+ then closeAllMenus mb+ else openNamedMenu f mb -- | Given a lens to access a menu bar and a handler to invoke on its -- currently open menu, invoke the handler if there is an open menu and