on develop help sign in
Merge branch 'develop' into develop
commit4bb5211f034df3b725eb26674fcf2a4f87a5eb51 authorElliot Cameron <3noch@users.noreply.github.com> dateFri 8 May 2020, 00:42 (6 years ago) parent18d0400430a211
4 files changed+33−10
ChangeLog.md+2−1 src-bin/example.hs+2−1 src/Reflex/Vty/Widget.hs+28−8 src/Reflex/Vty/Widget/Layout.hs+1
ChangeLog.md+2−1
@@ -1,8 +1,9 @@
11# Revision history for reflex-vty
22
33## 0.1.3.1
4−
54* Add `splitH` to implement horizontal functionality of `splitV`.
5+* Add `boxTitle`: a box with a title
6+* Update the text editing example to use `boxTitle`
67
78## 0.1.3.0
89* Add `mouseScroll` to capture scroll wheel events
src-bin/example.hs+2−1
@@ -97,7 +97,8 @@ testBoxes = do
9797 { _textInputConfig_initialValue =
9898 "This box is a text input. The box below responds to mouse drag inputs. You can also drag the separator between the boxes to resize them."
9999 }
100− textBox = boxStatic roundedBoxStyle $ multilineTextInput cfg
100+ textBox = boxTitle (pure roundedBoxStyle) "Text Edit" $
101+ multilineTextInput cfg
101102 dragBox = boxStatic roundedBoxStyle dragTest
102103 in splitVDrag (hRule doubleBoxStyle) textBox dragBox
103104 return ()
src/Reflex/Vty/Widget.hs+28−8
@@ -45,6 +45,7 @@ module Reflex.Vty.Widget
4545 , splitV
4646 , splitH
4747 , splitVDrag
48+ , boxTitle
4849 , box
4950 , boxStatic
5051 , RichTextConfig(..)
@@ -339,13 +340,13 @@ drag btn = do
339340 f Nothing = \case
340341 V.EvMouseDown x y btn' mods
341342 | btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods False
342− | otherwise -> Nothing
343+ | otherwise -> Nothing
343344 _ -> Nothing
344345 f (Just (Drag from _ _ mods end)) = \case
345346 V.EvMouseDown x y btn' mods'
346− | end -> Just $ Drag (x,y) (x,y) btn' mods' False
347− | btn == btn' -> Just $ Drag from (x,y) btn mods' False
348− | otherwise -> Nothing -- Ignore other buttons.
347+ | end && btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods' False
348+ | btn == btn' -> Just $ Drag from (x,y) btn mods' False
349+ | otherwise -> Nothing -- Ignore other buttons.
349350 V.EvMouseUp x y (Just btn')
350351 | end -> Nothing
351352 | btn == btn' -> Just $ Drag from (x,y) btn mods True
@@ -593,12 +594,13 @@ doubleBoxStyle = BoxStyle '╔' '═' '╗' '║' '╝' '═' '╚' '║'
593594roundedBoxStyle :: BoxStyle
594595roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
595596
596−-- | Draws a box in the provided style and a child widget inside of that box
597−box :: (Monad m, Reflex t, MonadNodeId m)
597+-- | Draws a titled box in the provided style and a child widget inside of that box
598+boxTitle :: (Monad m, Reflex t, MonadNodeId m)
598599 => Behavior t BoxStyle
600+ -> Text
599601 -> VtyWidget t m a
600602 -> VtyWidget t m a
601−box boxStyle child = do
603+boxTitle boxStyle title child = do
602604 dh <- displayHeight
603605 dw <- displayWidth
604606 let boxReg = DynRegion (pure 0) (pure 0) dw dh
@@ -613,7 +615,8 @@ box boxStyle child = do
613615 bottom = top + height - 1
614616 sides =
615617 [ withinImage (Region (left + 1) top (width - 2) 1) $
616− V.charFill V.defAttr (_boxStyle_n style) (width - 2) 1
618+ V.text' V.defAttr $
619+ hPadText title (_boxStyle_n style) (width - 2)
617620 , withinImage (Region right (top + 1) 1 (height - 2)) $
618621 V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
619622 , withinImage (Region (left + 1) bottom (width - 2) 1) $
@@ -632,6 +635,23 @@ box boxStyle child = do
632635 V.char V.defAttr (_boxStyle_sw style)
633636 ]
634637 in sides ++ if width > 1 && height > 1 then corners else []
638+ hPadText :: T.Text -> Char -> Int -> T.Text
639+ hPadText t c l = if lt >= l
640+ then t
641+ else left <> t <> right
642+ where
643+ lt = T.length t
644+ delta = l - lt
645+ mkHalf n = T.replicate (n `div` 2) (T.singleton c)
646+ left = mkHalf $ delta + 1
647+ right = mkHalf delta
648+
649+-- | A box without a title
650+box :: (Monad m, Reflex t, MonadNodeId m)
651+ => Behavior t BoxStyle
652+ -> VtyWidget t m a
653+ -> VtyWidget t m a
654+box boxStyle = boxTitle boxStyle mempty
635655
636656-- | A box whose style is static
637657boxStatic
src/Reflex/Vty/Widget/Layout.hs+1
@@ -78,6 +78,7 @@ newtype Layout t m a = Layout
7878 , MonadReflexCreateTrigger t
7979 , HasDisplaySize t
8080 , MonadNodeId
81+ , PostBuild t
8182 )
8283
8384instance MonadTrans (Layout t) where