on develop help sign in
theme box usage
9862dfbpdlla
src/Reflex/Vty/Widget.hs+3−3
@@ -237,9 +237,9 @@ regionSize :: Region -> (Int, Int)
237regionSize (Region _ _ w h) = (w, h)
237regionSize (Region _ _ w h) = (w, h)
238
238
239-- | Produces an 'Image' that fills a region with space characters
239-- | Produces an 'Image' that fills a region with space characters
240−regionBlankImage :: Region -> Image
240+regionBlankImage :: V.Attr -> Region -> Image
241−regionBlankImage r@(Region _ _ width height) =
241+regionBlankImage attr r@(Region _ _ width height) =
242− withinImage r $ V.charFill V.defAttr ' ' width height
242+ withinImage r $ V.charFill attr ' ' width height
243
243
244-- | A class for things that know their own display size dimensions
244-- | A class for things that know their own display size dimensions
245class (Reflex t, Monad m) => HasDisplayRegion t m | m -> t where
245class (Reflex t, Monad m) => HasDisplayRegion t m | m -> t where
src/Reflex/Vty/Widget/Box.hs+18−15
@@ -54,7 +54,7 @@ roundedBoxStyle :: BoxStyle
54roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
54roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
55
55
56-- | Draws a titled box in the provided style and a child widget inside of that box
56-- | 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)
58 => Behavior t BoxStyle
58 => Behavior t BoxStyle
59 -> Behavior t Text
59 -> Behavior t Text
60 -> m a
60 -> m a
@@ -62,36 +62,39 @@ boxTitle :: (Monad m, Reflex t ,HasDisplayRegion t m, HasImageWriter t m, HasInp
62boxTitle boxStyle title child = do
62boxTitle boxStyle title child = do
63 dh <- displayHeight
63 dh <- displayHeight
64 dw <- displayWidth
64 dw <- displayWidth
65+ bt <- theme
65 let boxReg = Region 0 0 <$> dw <*> dh
66 let boxReg = Region 0 0 <$> dw <*> dh
66 innerReg = Region 1 1 <$> (subtract 2 <$> dw) <*> (subtract 2 <$> dh)
67 innerReg = Region 1 1 <$> (subtract 2 <$> dw) <*> (subtract 2 <$> dh)
68+
67− tellImages (boxImages <$> title <*> boxStyle <*> current boxReg)
69+ tellImages (boxImages <$> bt <*> title <*> boxStyle <*> current boxReg)
68− tellImages (fmap (\r -> [regionBlankImage r]) (current innerReg))
70+ tellImages (ffor2 (current innerReg) bt (\r attr -> [regionBlankImage attr r]))
71+
69 pane innerReg (pure True) child
72 pane innerReg (pure True) child
70 where
73 where
71− boxImages :: Text -> BoxStyle -> Region -> [Image]
74+ boxImages :: V.Attr -> Text -> BoxStyle -> Region -> [Image]
72− boxImages title' style (Region left top width height) =
75+ boxImages attr title' style (Region left top width height) =
73 let right = left + width - 1
76 let right = left + width - 1
74 bottom = top + height - 1
77 bottom = top + height - 1
75 sides =
78 sides =
76 [ withinImage (Region (left + 1) top (width - 2) 1) $
79 [ withinImage (Region (left + 1) top (width - 2) 1) $
77− V.text' V.defAttr $
80+ V.text' attr $
78 hPadText title' (_boxStyle_n style) (width - 2)
81 hPadText title' (_boxStyle_n style) (width - 2)
79 , withinImage (Region right (top + 1) 1 (height - 2)) $
82 , 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)
81 , withinImage (Region (left + 1) bottom (width - 2) 1) $
84 , 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
83 , withinImage (Region left (top + 1) 1 (height - 2)) $
86 , 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)
85 ]
88 ]
86 corners =
89 corners =
87 [ withinImage (Region left top 1 1) $
90 [ withinImage (Region left top 1 1) $
88− V.char V.defAttr (_boxStyle_nw style)
91+ V.char attr (_boxStyle_nw style)
89 , withinImage (Region right top 1 1) $
92 , withinImage (Region right top 1 1) $
90− V.char V.defAttr (_boxStyle_ne style)
93+ V.char attr (_boxStyle_ne style)
91 , withinImage (Region right bottom 1 1) $
94 , withinImage (Region right bottom 1 1) $
92− V.char V.defAttr (_boxStyle_se style)
95+ V.char attr (_boxStyle_se style)
93 , withinImage (Region left bottom 1 1) $
96 , withinImage (Region left bottom 1 1) $
94− V.char V.defAttr (_boxStyle_sw style)
97+ V.char attr (_boxStyle_sw style)
95 ]
98 ]
96 in sides ++ if width > 1 && height > 1 then corners else []
99 in sides ++ if width > 1 && height > 1 then corners else []
97 hPadText :: T.Text -> Char -> Int -> T.Text
100 hPadText :: T.Text -> Char -> Int -> T.Text
@@ -106,7 +109,7 @@ boxTitle boxStyle title child = do
106 right = mkHalf delta
109 right = mkHalf delta
107
110
108-- | A box without a title
111-- | 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)
110 => Behavior t BoxStyle
113 => Behavior t BoxStyle
111 -> m a
114 -> m a
112 -> m a
115 -> m a
@@ -114,7 +117,7 @@ box boxStyle = boxTitle boxStyle mempty
114
117
115-- | A box whose style is static
118-- | A box whose style is static
116boxStatic
119boxStatic
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)
118 => BoxStyle
121 => BoxStyle
119 -> m a
122 -> m a
120 -> m a
123 -> m a