on develop help sign in
Make box style a behavior; Add boxStatic for unchanging style
0ee701eAli Abrar
src-bin/example.hs+5−5
@@ -80,9 +80,9 @@ testBoxes = do
80 size <- displaySize
80 size <- displaySize
81 let region1 = fmap (\(w,h) -> Region (w `div` 6) (h `div` 6) (w `div` 2) (h `div` 2)) size
81 let region1 = fmap (\(w,h) -> Region (w `div` 6) (h `div` 6) (w `div` 2) (h `div` 2)) size
82 region2 = fmap (\(w,h) -> Region (w `div` 4) (h `div` 4) (2 * (w `div` 3)) (2*(h `div` 3))) size
82 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
83+ pane region1 (constDyn False) . boxStatic singleBoxStyle $ debugInput
84− _ <- pane region2 (constDyn True) . box singleBoxStyle $
84+ _ <- pane region2 (constDyn True) . boxStatic singleBoxStyle $
85− splitVDrag (hRule doubleBoxStyle) (box roundedBoxStyle $ multilineTextInput def) (box roundedBoxStyle dragTest)
85+ splitVDrag (hRule doubleBoxStyle) (boxStatic roundedBoxStyle $ multilineTextInput def) (boxStatic roundedBoxStyle dragTest)
86 return ()
86 return ()
87
87
88debugFocus :: (Reflex t, Monad m) => VtyWidget t m ()
88debugFocus :: (Reflex t, Monad m) => VtyWidget t m ()
@@ -101,7 +101,7 @@ dragTest = do
101 text $ T.pack <$> lastEvent
101 text $ T.pack <$> lastEvent
102
102
103testStringBox :: (Reflex t, Monad m) => VtyWidget t m ()
103testStringBox :: (Reflex t, Monad m) => VtyWidget t m ()
104−testStringBox = box singleBoxStyle .
104+testStringBox = boxStatic singleBoxStyle .
105 text . pure . T.pack . take 500 $ cycle ('\n' : ['a'..'z'])
105 text . pure . T.pack . take 500 $ cycle ('\n' : ['a'..'z'])
106
106
107data Todo = Todo
107data Todo = Todo
@@ -124,7 +124,7 @@ checkbox v0 = do
124
124
125button :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m (Event t ())
125button :: (Reflex t, Monad m) => Behavior t Text -> VtyWidget t m (Event t ())
126button t = do
126button t = do
127− box roundedBoxStyle $ text t
127+ boxStatic roundedBoxStyle $ text t
128 fmap (() <$) mouseUp
128 fmap (() <$) mouseUp
129
129
130data TodoOutput t = TodoOutput
130data TodoOutput t = TodoOutput
src/Reflex/Vty/Widget.hs+14−5
@@ -43,6 +43,7 @@ module Reflex.Vty.Widget
43 , splitV
43 , splitV
44 , splitVDrag
44 , splitVDrag
45 , box
45 , box
46+ , boxStatic
46 , text
47 , text
47 , display
48 , display
48 , hyphenBoxStyle
49 , hyphenBoxStyle
@@ -489,19 +490,19 @@ roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
489
490
490-- | Draws a box in the provided style and a child widget inside of that box
491-- | Draws a box in the provided style and a child widget inside of that box
491box :: (Monad m, Reflex t)
492box :: (Monad m, Reflex t)
492− => BoxStyle
493+ => Behavior t BoxStyle
493 -> VtyWidget t m a
494 -> VtyWidget t m a
494 -> VtyWidget t m a
495 -> VtyWidget t m a
495−box style child = do
496+box boxStyle child = do
496 sz <- displaySize
497 sz <- displaySize
497 let boxReg = ffor (current sz) $ \(w,h) -> Region 0 0 w h
498 let boxReg = ffor (current sz) $ \(w,h) -> Region 0 0 w h
498 innerReg = ffor sz $ \(w,h) -> Region 1 1 (w - 2) (h - 2)
499 innerReg = ffor sz $ \(w,h) -> Region 1 1 (w - 2) (h - 2)
499− tellImages (fmap boxImages boxReg)
500+ tellImages (boxImages <$> boxStyle <*> boxReg)
500 tellImages (fmap (\r -> [regionBlankImage r]) (current innerReg))
501 tellImages (fmap (\r -> [regionBlankImage r]) (current innerReg))
501 pane innerReg (pure True) child
502 pane innerReg (pure True) child
502 where
503 where
503− boxImages :: Region -> [Image]
504+ boxImages :: BoxStyle -> Region -> [Image]
504− boxImages (Region left top width height) =
505+ boxImages style (Region left top width height) =
505 let right = left + width - 1
506 let right = left + width - 1
506 bottom = top + height - 1
507 bottom = top + height - 1
507 sides =
508 sides =
@@ -526,6 +527,14 @@ box style child = do
526 ]
527 ]
527 in sides ++ if width > 1 && height > 1 then corners else []
528 in sides ++ if width > 1 && height > 1 then corners else []
528
529
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+
529-- | Renders text, wrapped to the container width
538-- | Renders text, wrapped to the container width
530text
539text
531 :: (Reflex t, Monad m)
540 :: (Reflex t, Monad m)