@@ -44,6 +44,7 @@ module Reflex.Vty.Widget
46 , splitVDrag
46 , splitVDrag
48 , boxStatic
49 , boxStatic
49 , RichTextConfig(..)
50 , RichTextConfig(..)
@@ -563,12 +564,13 @@ doubleBoxStyle = BoxStyle '╔' '═' '╗' '║' '╝' '═' '╚' '║'
563roundedBoxStyle :: BoxStyle
564roundedBoxStyle :: BoxStyle
564roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
565roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
566−-- | Draws a box in the provided style and a child widget inside of that box
567+-- | Draws a titled box in the provided style and a child widget inside of that box
567−box :: (Monad m, Reflex t, MonadNodeId m)
568+boxTitle :: (Monad m, Reflex t, MonadNodeId m)
568 => Behavior t BoxStyle
569 => Behavior t BoxStyle
569 -> VtyWidget t m a
571 -> VtyWidget t m a
570 -> VtyWidget t m a
572 -> VtyWidget t m a
571−box boxStyle child = do
573+boxTitle boxStyle title child = do
572 dh <- displayHeight
574 dh <- displayHeight
573 dw <- displayWidth
575 dw <- displayWidth
574 let boxReg = DynRegion (pure 0) (pure 0) dw dh
576 let boxReg = DynRegion (pure 0) (pure 0) dw dh
@@ -583,7 +585,8 @@ box boxStyle child = do
583 bottom = top + height - 1
585 bottom = top + height - 1
585 [ withinImage (Region (left + 1) top (width - 2) 1) $
587 [ withinImage (Region (left + 1) top (width - 2) 1) $
586− V.charFill V.defAttr (_boxStyle_n style) (width - 2) 1
589+ hPadText title (_boxStyle_n style) (width - 2)
587 , withinImage (Region right (top + 1) 1 (height - 2)) $
590 , withinImage (Region right (top + 1) 1 (height - 2)) $
588 V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
591 V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
589 , withinImage (Region (left + 1) bottom (width - 2) 1) $
592 , withinImage (Region (left + 1) bottom (width - 2) 1) $
@@ -602,6 +605,23 @@ box boxStyle child = do
602 V.char V.defAttr (_boxStyle_sw style)
605 V.char V.defAttr (_boxStyle_sw style)
604 in sides ++ if width > 1 && height > 1 then corners else []
607 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
611+ else left <> t <> right
615+ mkHalf n = T.replicate (n `div` 2) (T.singleton c)
616+ left = mkHalf $ delta + 1
617+ right = mkHalf delta
619+-- | A box without a title
620+box :: (Monad m, Reflex t, MonadNodeId m)
621+ => Behavior t BoxStyle
624+box boxStyle = boxTitle boxStyle mempty
606-- | A box whose style is static
626-- | A box whose style is static