on develop help sign in
Merge pull request #17 from Wheatwizard/develop

Add splitH to complement existing splitV.

commit613a7865df0ecb80a6cffb032562c859a9dc27c3 authorElliot Cameron <3noch@users.noreply.github.com> dateFri 8 May 2020, 01:11 (6 years ago) parent430a2114bb5211
2 files changed+31
ChangeLog.md+1 src/Reflex/Vty/Widget.hs+30
ChangeLog.md+1
@@ -1,6 +1,7 @@
11# Revision history for reflex-vty
22
33## 0.1.3.1
4+* Add `splitH` to implement horizontal functionality of `splitV`.
45* Add `boxTitle`: a box with a title
56* Update the text editing example to use `boxTitle`
67
src/Reflex/Vty/Widget.hs+30
@@ -43,6 +43,7 @@ module Reflex.Vty.Widget
4343 , mouseScroll
4444 , pane
4545 , splitV
46+ , splitH
4647 , splitVDrag
4748 , boxTitle
4849 , box
@@ -475,6 +476,35 @@ splitV sizeFunD focD wA wB = do
475476 rb <- pane regB (snd <$> focD) wB
476477 return (ra,rb)
477478
479+-- | A plain split of the available space into horizontally stacked panes.
480+-- No visual separator is built in here.
481+splitH :: (Reflex t, Monad m, MonadNodeId m)
482+ => Dynamic t (Int -> Int)
483+ -- ^ Function used to determine size of first pane based on available size
484+ -> Dynamic t (Bool, Bool)
485+ -- ^ How to focus the two sub-panes, given that we are focused.
486+ -> VtyWidget t m a
487+ -- ^ Widget for first pane
488+ -> VtyWidget t m b
489+ -- ^ Widget for second pane
490+ -> VtyWidget t m (a,b)
491+splitH sizeFunD focD wA wB = do
492+ dw <- displayWidth
493+ dh <- displayHeight
494+ let regA = DynRegion
495+ { _dynRegion_left = pure 0
496+ , _dynRegion_top = pure 0
497+ , _dynRegion_width = sizeFunD <*> dw
498+ , _dynRegion_height = dh
499+ }
500+ regB = DynRegion
501+ { _dynRegion_left = _dynRegion_width regA
502+ , _dynRegion_top = pure 0
503+ , _dynRegion_width = liftA2 (-) dw (_dynRegion_width regA)
504+ , _dynRegion_height = dh
505+ }
506+ liftA2 (,) (pane regA (fmap fst focD) wA) (pane regB (fmap snd focD) wB)
507+
478508-- | A split of the available space into two parts with a draggable separator.
479509-- Starts with half the space allocated to each, and the first pane has focus.
480510-- Clicking in a pane switches focus.