@@ -45,6 +45,7 @@ module Reflex.Vty.Widget
4545 , splitV
4646 , splitH
4747 , splitVDrag
48+ , boxTitle
4849 , box
4950 , boxStatic
5051 , RichTextConfig(..)
@@ -339,13 +340,13 @@ drag btn = do
339340 f Nothing = \case
340341 V.EvMouseDown x y btn' mods
341342 | btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods False
342− | otherwise -> Nothing
343+ | otherwise -> Nothing
343344 _ -> Nothing
344345 f (Just (Drag from _ _ mods end)) = \case
345346 V.EvMouseDown x y btn' mods'
346− | end -> 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.
347+ | end && btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods' False
348+ | btn == btn' -> Just $ Drag from (x,y) btn mods' False
349+ | otherwise -> Nothing -- Ignore other buttons.
349350 V.EvMouseUp x y (Just btn')
350351 | end -> Nothing
351352 | btn == btn' -> Just $ Drag from (x,y) btn mods True
@@ -593,12 +594,13 @@ doubleBoxStyle = BoxStyle '╔' '═' '╗' '║' '╝' '═' '╚' '║'
593594roundedBoxStyle :: BoxStyle
594595roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
595596
596−-- | Draws a box in the provided style and a child widget inside of that box
597−box :: (Monad m, Reflex t, MonadNodeId m)
597+-- | Draws a titled box in the provided style and a child widget inside of that box
598+boxTitle :: (Monad m, Reflex t, MonadNodeId m)
598599 => Behavior t BoxStyle
600+ -> Text
599601 -> VtyWidget t m a
600602 -> VtyWidget t m a
601−box boxStyle child = do
603+boxTitle boxStyle title child = do
602604 dh <- displayHeight
603605 dw <- displayWidth
604606 let boxReg = DynRegion (pure 0) (pure 0) dw dh
@@ -613,7 +615,8 @@ box boxStyle child = do
613615 bottom = top + height - 1
614616 sides =
615617 [ withinImage (Region (left + 1) top (width - 2) 1) $
616− V.charFill V.defAttr (_boxStyle_n style) (width - 2) 1
618+ V.text' V.defAttr $
619+ hPadText title (_boxStyle_n style) (width - 2)
617620 , withinImage (Region right (top + 1) 1 (height - 2)) $
618621 V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
619622 , withinImage (Region (left + 1) bottom (width - 2) 1) $
@@ -632,6 +635,23 @@ box boxStyle child = do
632635 V.char V.defAttr (_boxStyle_sw style)
633636 ]
634637 in sides ++ if width > 1 && height > 1 then corners else []
638+ hPadText :: T.Text -> Char -> Int -> T.Text
639+ hPadText t c l = if lt >= l
640+ then t
641+ else left <> t <> right
642+ where
643+ lt = T.length t
644+ delta = l - lt
645+ mkHalf n = T.replicate (n `div` 2) (T.singleton c)
646+ left = mkHalf $ delta + 1
647+ right = mkHalf delta
648+
649+-- | A box without a title
650+box :: (Monad m, Reflex t, MonadNodeId m)
651+ => Behavior t BoxStyle
652+ -> VtyWidget t m a
653+ -> VtyWidget t m a
654+box boxStyle = boxTitle boxStyle mempty
635655
636656-- | A box whose style is static
637657boxStatic