@@ -44,6 +44,7 @@ module Reflex.Vty.Widget
4444 , pane
4545 , splitV
4646 , splitVDrag
47+ , boxTitle
4748 , box
4849 , boxStatic
4950 , RichTextConfig(..)
@@ -338,13 +339,13 @@ drag btn = do
338339 f Nothing = \case
339340 V.EvMouseDown x y btn' mods
340341 | btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods False
341− | otherwise -> Nothing
342+ | otherwise -> Nothing
342343 _ -> Nothing
343344 f (Just (Drag from _ _ mods end)) = \case
344345 V.EvMouseDown x y btn' mods'
345− | end -> Just $ Drag (x,y) (x,y) btn' mods' False
346− | btn == btn' -> Just $ Drag from (x,y) btn mods' False
347− | otherwise -> Nothing -- Ignore other buttons.
346+ | end && btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods' False
347+ | btn == btn' -> Just $ Drag from (x,y) btn mods' False
348+ | otherwise -> Nothing -- Ignore other buttons.
348349 V.EvMouseUp x y (Just btn')
349350 | end -> Nothing
350351 | btn == btn' -> Just $ Drag from (x,y) btn mods True
@@ -563,12 +564,13 @@ doubleBoxStyle = BoxStyle '╔' '═' '╗' '║' '╝' '═' '╚' '║'
563564roundedBoxStyle :: BoxStyle
564565roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
565566
566−-- | Draws a box in the provided style and a child widget inside of that box
567−box :: (Monad m, Reflex t, MonadNodeId m)
567+-- | Draws a titled box in the provided style and a child widget inside of that box
568+boxTitle :: (Monad m, Reflex t, MonadNodeId m)
568569 => Behavior t BoxStyle
570+ -> Text
569571 -> VtyWidget t m a
570572 -> VtyWidget t m a
571−box boxStyle child = do
573+boxTitle boxStyle title child = do
572574 dh <- displayHeight
573575 dw <- displayWidth
574576 let boxReg = DynRegion (pure 0) (pure 0) dw dh
@@ -583,7 +585,8 @@ box boxStyle child = do
583585 bottom = top + height - 1
584586 sides =
585587 [ withinImage (Region (left + 1) top (width - 2) 1) $
586− V.charFill V.defAttr (_boxStyle_n style) (width - 2) 1
588+ V.text' V.defAttr $
589+ hPadText title (_boxStyle_n style) (width - 2)
587590 , withinImage (Region right (top + 1) 1 (height - 2)) $
588591 V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
589592 , withinImage (Region (left + 1) bottom (width - 2) 1) $
@@ -602,6 +605,23 @@ box boxStyle child = do
602605 V.char V.defAttr (_boxStyle_sw style)
603606 ]
604607 in sides ++ if width > 1 && height > 1 then corners else []
608+ hPadText :: T.Text -> Char -> Int -> T.Text
609+ hPadText t c l = if lt >= l
610+ then t
611+ else left <> t <> right
612+ where
613+ lt = T.length t
614+ delta = l - lt
615+ mkHalf n = T.replicate (n `div` 2) (T.singleton c)
616+ left = mkHalf $ delta + 1
617+ right = mkHalf delta
618+
619+-- | A box without a title
620+box :: (Monad m, Reflex t, MonadNodeId m)
621+ => Behavior t BoxStyle
622+ -> VtyWidget t m a
623+ -> VtyWidget t m a
624+box boxStyle = boxTitle boxStyle mempty
605625
606626-- | A box whose style is static
607627boxStatic