on develop help sign in
Make box style a behavior; Add boxStatic for unchanging style
commit0ee701e924c1d2a648a530bc55360cb3a100a60c authorAli Abrar <aliabrar@gmail.com> dateMon 5 Nov 2018, 00:19 (8 years ago) parent6fc2815
2 files changed+19−10
src-bin/example.hs+5−5 src/Reflex/Vty/Widget.hs+14−5
src-bin/example.hs+5−5
@@ -80,9 +80,9 @@ testBoxes = do
8080 size <- displaySize
8181 let region1 = fmap (\(w,h) -> Region (w `div` 6) (h `div` 6) (w `div` 2) (h `div` 2)) size
8282 region2 = fmap (\(w,h) -> Region (w `div` 4) (h `div` 4) (2 * (w `div` 3)) (2*(h `div` 3))) size
83− pane region1 (constDyn False) . box singleBoxStyle $ debugInput
84− _ <- pane region2 (constDyn True) . box singleBoxStyle $
85− splitVDrag (hRule doubleBoxStyle) (box roundedBoxStyle $ multilineTextInput def) (box roundedBoxStyle dragTest)
83+ pane region1 (constDyn False) . boxStatic singleBoxStyle $ debugInput
84+ _ <- pane region2 (constDyn True) . boxStatic singleBoxStyle $
85+ splitVDrag (hRule doubleBoxStyle) (boxStatic roundedBoxStyle $ multilineTextInput def) (boxStatic roundedBoxStyle dragTest)
8686 return ()
8787
8888debugFocus :: (Reflex t, Monad m) => VtyWidget t m ()
@@ -101,7 +101,7 @@ dragTest = do
101101 text $ T.pack <$> lastEvent
102102
103103testStringBox :: (Reflex t, Monad m) => VtyWidget t m ()
104−testStringBox = box singleBoxStyle .
104+testStringBox = boxStatic singleBoxStyle .
105105 text . pure . T.pack . take 500 $ cycle ('\n' : ['a'..'z'])
106106
107107data Todo = Todo
@@ -124,7 +124,7 @@ checkbox v0 = do
124124
125125button :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m (Event t ())
126126button t = do
127− box roundedBoxStyle $ text t
127+ boxStatic roundedBoxStyle $ text t
128128 fmap (() <$) mouseUp
129129
130130data TodoOutput t = TodoOutput
src/Reflex/Vty/Widget.hs+14−5
@@ -43,6 +43,7 @@ module Reflex.Vty.Widget
4343 , splitV
4444 , splitVDrag
4545 , box
46+ , boxStatic
4647 , text
4748 , display
4849 , hyphenBoxStyle
@@ -489,19 +490,19 @@ roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
489490
490491-- | Draws a box in the provided style and a child widget inside of that box
491492box :: (Monad m, Reflex t)
492− => BoxStyle
493+ => Behavior t BoxStyle
493494 -> VtyWidget t m a
494495 -> VtyWidget t m a
495−box style child = do
496+box boxStyle child = do
496497 sz <- displaySize
497498 let boxReg = ffor (current sz) $ \(w,h) -> Region 0 0 w h
498499 innerReg = ffor sz $ \(w,h) -> Region 1 1 (w - 2) (h - 2)
499− tellImages (fmap boxImages boxReg)
500+ tellImages (boxImages <$> boxStyle <*> boxReg)
500501 tellImages (fmap (\r -> [regionBlankImage r]) (current innerReg))
501502 pane innerReg (pure True) child
502503 where
503− boxImages :: Region -> [Image]
504− boxImages (Region left top width height) =
504+ boxImages :: BoxStyle -> Region -> [Image]
505+ boxImages style (Region left top width height) =
505506 let right = left + width - 1
506507 bottom = top + height - 1
507508 sides =
@@ -526,6 +527,14 @@ box style child = do
526527 ]
527528 in sides ++ if width > 1 && height > 1 then corners else []
528529
530+-- | A box whose style is static
531+boxStatic
532+ :: (Reflex t, Monad m)
533+ => BoxStyle
534+ -> VtyWidget t m a
535+ -> VtyWidget t m a
536+boxStatic = box . pure
537+
529538-- | Renders text, wrapped to the container width
530539text
531540 :: (Reflex t, Monad m)