on develop help sign in
theme box usage
commit9862dfb4e182518a14e160398426c1d8af43c65e authorpdlla <chippermonky@gmail.com> dateSun 11 Apr 2021, 16:46 (6 years ago) parent214bfb1
2 files changed+21−18
src/Reflex/Vty/Widget.hs+3−3 src/Reflex/Vty/Widget/Box.hs+18−15
src/Reflex/Vty/Widget.hs+3−3
@@ -237,9 +237,9 @@ regionSize :: Region -> (Int, Int)
237237regionSize (Region _ _ w h) = (w, h)
238238
239239-- | Produces an 'Image' that fills a region with space characters
240−regionBlankImage :: Region -> Image
241−regionBlankImage r@(Region _ _ width height) =
242− withinImage r $ V.charFill V.defAttr ' ' width height
240+regionBlankImage :: V.Attr -> Region -> Image
241+regionBlankImage attr r@(Region _ _ width height) =
242+ withinImage r $ V.charFill attr ' ' width height
243243
244244-- | A class for things that know their own display size dimensions
245245class (Reflex t, Monad m) => HasDisplayRegion t m | m -> t where
src/Reflex/Vty/Widget/Box.hs+18−15
@@ -54,7 +54,7 @@ roundedBoxStyle :: BoxStyle
5454roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
5555
5656-- | Draws a titled box in the provided style and a child widget inside of that box
57−boxTitle :: (Monad m, Reflex t ,HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
57+boxTitle :: (Monad m, Reflex t ,HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m, HasTheme t m)
5858 => Behavior t BoxStyle
5959 -> Behavior t Text
6060 -> m a
@@ -62,36 +62,39 @@ boxTitle :: (Monad m, Reflex t ,HasDisplayRegion t m, HasImageWriter t m, HasInp
6262boxTitle boxStyle title child = do
6363 dh <- displayHeight
6464 dw <- displayWidth
65+ bt <- theme
6566 let boxReg = Region 0 0 <$> dw <*> dh
6667 innerReg = Region 1 1 <$> (subtract 2 <$> dw) <*> (subtract 2 <$> dh)
67− tellImages (boxImages <$> title <*> boxStyle <*> current boxReg)
68− tellImages (fmap (\r -> [regionBlankImage r]) (current innerReg))
68+
69+ tellImages (boxImages <$> bt <*> title <*> boxStyle <*> current boxReg)
70+ tellImages (ffor2 (current innerReg) bt (\r attr -> [regionBlankImage attr r]))
71+
6972 pane innerReg (pure True) child
7073 where
71− boxImages :: Text -> BoxStyle -> Region -> [Image]
72− boxImages title' style (Region left top width height) =
74+ boxImages :: V.Attr -> Text -> BoxStyle -> Region -> [Image]
75+ boxImages attr title' style (Region left top width height) =
7376 let right = left + width - 1
7477 bottom = top + height - 1
7578 sides =
7679 [ withinImage (Region (left + 1) top (width - 2) 1) $
77− V.text' V.defAttr $
80+ V.text' attr $
7881 hPadText title' (_boxStyle_n style) (width - 2)
7982 , withinImage (Region right (top + 1) 1 (height - 2)) $
80− V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
83+ V.charFill attr (_boxStyle_e style) 1 (height - 2)
8184 , withinImage (Region (left + 1) bottom (width - 2) 1) $
82− V.charFill V.defAttr (_boxStyle_s style) (width - 2) 1
85+ V.charFill attr (_boxStyle_s style) (width - 2) 1
8386 , withinImage (Region left (top + 1) 1 (height - 2)) $
84− V.charFill V.defAttr (_boxStyle_w style) 1 (height - 2)
87+ V.charFill attr (_boxStyle_w style) 1 (height - 2)
8588 ]
8689 corners =
8790 [ withinImage (Region left top 1 1) $
88− V.char V.defAttr (_boxStyle_nw style)
91+ V.char attr (_boxStyle_nw style)
8992 , withinImage (Region right top 1 1) $
90− V.char V.defAttr (_boxStyle_ne style)
93+ V.char attr (_boxStyle_ne style)
9194 , withinImage (Region right bottom 1 1) $
92− V.char V.defAttr (_boxStyle_se style)
95+ V.char attr (_boxStyle_se style)
9396 , withinImage (Region left bottom 1 1) $
94− V.char V.defAttr (_boxStyle_sw style)
97+ V.char attr (_boxStyle_sw style)
9598 ]
9699 in sides ++ if width > 1 && height > 1 then corners else []
97100 hPadText :: T.Text -> Char -> Int -> T.Text
@@ -106,7 +109,7 @@ boxTitle boxStyle title child = do
106109 right = mkHalf delta
107110
108111-- | A box without a title
109−box :: (Monad m, Reflex t, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
112+box :: (Monad m, Reflex t, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m, HasTheme t m)
110113 => Behavior t BoxStyle
111114 -> m a
112115 -> m a
@@ -114,7 +117,7 @@ box boxStyle = boxTitle boxStyle mempty
114117
115118-- | A box whose style is static
116119boxStatic
117− :: (Monad m, Reflex t, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m)
120+ :: (Monad m, Reflex t, HasDisplayRegion t m, HasImageWriter t m, HasInput t m, HasFocusReader t m, HasTheme t m)
118121 => BoxStyle
119122 -> m a
120123 -> m a