on develop help sign in
Merge branch 'develop' into develop
commit7d75825cf6243064ad5ae29fb0adad3cd4d21de0 authorElliot Cameron <3noch@users.noreply.github.com> dateTue 5 May 2020, 13:29 (6 years ago) parent92b734fcb6c954
3 files changed+34−9
ChangeLog.md+4 src-bin/example.hs+2−1 src/Reflex/Vty/Widget.hs+28−8
ChangeLog.md+4
@@ -1,5 +1,9 @@
11# Revision history for reflex-vty
22
3+## 0.1.3.1
4+* Add `boxTitle`: a box with a title
5+* Update the text editing example to use `boxTitle`
6+
37## 0.1.3.0
48* Add `mouseScroll` to capture scroll wheel events
59* Add `scrollableText`: a text display widget that can be scrolled using the mouse or keyboard
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
@@ -44,6 +44,7 @@ module Reflex.Vty.Widget
4444 , pane
4545 , splitV
4646 , splitVDrag
47+ , boxTitle
4748 , box
4849 , boxStatic
4950 , RichTextConfig(..)
@@ -338,13 +339,13 @@ drag btn = do
338339 f Nothing = \case
339340 V.EvMouseDown x y btn' mods
340341 | btn == btn' -> Just $ Drag (x,y) (x,y) btn' mods False
341− | otherwise -> Nothing
342+ | otherwise -> Nothing
342343 _ -> Nothing
343344 f (Just (Drag from _ _ mods end)) = \case
344345 V.EvMouseDown x y btn' mods'
345− | end -> Just $ Drag (x,y) (x,y) btn' mods' False
346− | btn == btn' -> Just $ Drag from (x,y) btn mods' False
347− | otherwise -> Nothing -- Ignore other buttons.
346+ | end && btn == btn' -> 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.
348349 V.EvMouseUp x y (Just btn')
349350 | end -> Nothing
350351 | btn == btn' -> Just $ Drag from (x,y) btn mods True
@@ -563,12 +564,13 @@ doubleBoxStyle = BoxStyle '╔' '═' '╗' '║' '╝' '═' '╚' '║'
563564roundedBoxStyle :: BoxStyle
564565roundedBoxStyle = BoxStyle '╭' '─' '╮' '│' '╯' '─' '╰' '│'
565566
566−-- | Draws a box in the provided style and a child widget inside of that box
567−box :: (Monad m, Reflex t, MonadNodeId m)
567+-- | Draws a titled box in the provided style and a child widget inside of that box
568+boxTitle :: (Monad m, Reflex t, MonadNodeId m)
568569 => Behavior t BoxStyle
570+ -> Text
569571 -> VtyWidget t m a
570572 -> VtyWidget t m a
571−box boxStyle child = do
573+boxTitle boxStyle title child = do
572574 dh <- displayHeight
573575 dw <- displayWidth
574576 let boxReg = DynRegion (pure 0) (pure 0) dw dh
@@ -583,7 +585,8 @@ box boxStyle child = do
583585 bottom = top + height - 1
584586 sides =
585587 [ withinImage (Region (left + 1) top (width - 2) 1) $
586− V.charFill V.defAttr (_boxStyle_n style) (width - 2) 1
588+ V.text' V.defAttr $
589+ hPadText title (_boxStyle_n style) (width - 2)
587590 , withinImage (Region right (top + 1) 1 (height - 2)) $
588591 V.charFill V.defAttr (_boxStyle_e style) 1 (height - 2)
589592 , withinImage (Region (left + 1) bottom (width - 2) 1) $
@@ -602,6 +605,23 @@ box boxStyle child = do
602605 V.char V.defAttr (_boxStyle_sw style)
603606 ]
604607 in sides ++ if width > 1 && height > 1 then corners else []
608+ hPadText :: T.Text -> Char -> Int -> T.Text
609+ hPadText t c l = if lt >= l
610+ then t
611+ else left <> t <> right
612+ where
613+ lt = T.length t
614+ delta = l - lt
615+ mkHalf n = T.replicate (n `div` 2) (T.singleton c)
616+ left = mkHalf $ delta + 1
617+ right = mkHalf delta
618+
619+-- | A box without a title
620+box :: (Monad m, Reflex t, MonadNodeId m)
621+ => Behavior t BoxStyle
622+ -> VtyWidget t m a
623+ -> VtyWidget t m a
624+box boxStyle = boxTitle boxStyle mempty
605625
606626-- | A box whose style is static
607627boxStatic