2015-07-04 01:49:33 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
module Main where
|
|
|
|
|
2016-05-09 04:05:30 +03:00
|
|
|
import Lens.Micro ((^.), (&), (%~))
|
|
|
|
import Lens.Micro.TH (makeLenses)
|
2015-07-04 01:49:33 +03:00
|
|
|
import Control.Monad (void)
|
2015-07-10 23:20:05 +03:00
|
|
|
import qualified Graphics.Vty as V
|
2015-07-04 01:49:33 +03:00
|
|
|
|
2015-07-10 23:20:05 +03:00
|
|
|
import qualified Brick.Types as T
|
2016-11-21 05:22:52 +03:00
|
|
|
import Brick.Types (locationRowL, locationColumnL, Widget)
|
2015-07-10 23:20:05 +03:00
|
|
|
import qualified Brick.Main as M
|
|
|
|
import qualified Brick.Widgets.Border as B
|
2016-06-11 01:01:28 +03:00
|
|
|
import qualified Brick.Widgets.Center as C
|
2015-08-20 05:40:06 +03:00
|
|
|
import Brick.Widgets.Core
|
|
|
|
( translateBy
|
2015-08-20 18:36:39 +03:00
|
|
|
, str
|
2015-07-10 23:20:05 +03:00
|
|
|
)
|
2017-01-25 00:48:45 +03:00
|
|
|
import Brick.AttrMap
|
|
|
|
( attrMap
|
|
|
|
)
|
2015-07-04 01:49:33 +03:00
|
|
|
|
|
|
|
data St =
|
2015-07-10 23:20:05 +03:00
|
|
|
St { _topLayerLocation :: T.Location
|
|
|
|
, _bottomLayerLocation :: T.Location
|
2015-07-04 01:49:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
makeLenses ''St
|
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
drawUi :: St -> [Widget ()]
|
2015-07-04 01:49:33 +03:00
|
|
|
drawUi st =
|
2016-06-11 01:01:28 +03:00
|
|
|
[ C.centerLayer $
|
2016-09-18 20:21:43 +03:00
|
|
|
B.border $ str "This layer is centered but other\nlayers are placed underneath it."
|
2016-06-11 01:01:28 +03:00
|
|
|
, topLayer st
|
2015-07-04 01:49:33 +03:00
|
|
|
, bottomLayer st
|
|
|
|
]
|
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
topLayer :: St -> Widget ()
|
2015-07-04 01:49:33 +03:00
|
|
|
topLayer st =
|
|
|
|
translateBy (st^.topLayerLocation) $
|
2015-08-20 18:36:39 +03:00
|
|
|
B.border $ str "Top layer\n(Arrow keys move)"
|
2015-07-04 01:49:33 +03:00
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
bottomLayer :: St -> Widget ()
|
2015-07-04 01:49:33 +03:00
|
|
|
bottomLayer st =
|
|
|
|
translateBy (st^.bottomLayerLocation) $
|
2015-08-20 18:36:39 +03:00
|
|
|
B.border $ str "Bottom layer\n(Ctrl-arrow keys move)"
|
2015-07-04 01:49:33 +03:00
|
|
|
|
2016-10-26 06:19:31 +03:00
|
|
|
appEvent :: St -> T.BrickEvent () e -> T.EventM () (T.Next St)
|
2016-11-21 05:22:52 +03:00
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KDown [])) =
|
|
|
|
M.continue $ st & topLayerLocation.locationRowL %~ (+ 1)
|
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KUp [])) =
|
|
|
|
M.continue $ st & topLayerLocation.locationRowL %~ (subtract 1)
|
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KRight [])) =
|
|
|
|
M.continue $ st & topLayerLocation.locationColumnL %~ (+ 1)
|
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KLeft [])) =
|
|
|
|
M.continue $ st & topLayerLocation.locationColumnL %~ (subtract 1)
|
2015-07-04 02:04:23 +03:00
|
|
|
|
2016-11-21 05:22:52 +03:00
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KDown [V.MCtrl])) =
|
|
|
|
M.continue $ st & bottomLayerLocation.locationRowL %~ (+ 1)
|
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KUp [V.MCtrl])) =
|
|
|
|
M.continue $ st & bottomLayerLocation.locationRowL %~ (subtract 1)
|
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KRight [V.MCtrl])) =
|
|
|
|
M.continue $ st & bottomLayerLocation.locationColumnL %~ (+ 1)
|
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KLeft [V.MCtrl])) =
|
|
|
|
M.continue $ st & bottomLayerLocation.locationColumnL %~ (subtract 1)
|
2015-07-04 02:04:23 +03:00
|
|
|
|
2016-10-26 06:19:31 +03:00
|
|
|
appEvent st (T.VtyEvent (V.EvKey V.KEsc [])) = M.halt st
|
2015-07-10 23:20:05 +03:00
|
|
|
appEvent st _ = M.continue st
|
2015-07-04 01:49:33 +03:00
|
|
|
|
2016-10-26 06:19:31 +03:00
|
|
|
app :: M.App St e ()
|
2015-07-04 01:49:33 +03:00
|
|
|
app =
|
2015-07-10 23:20:05 +03:00
|
|
|
M.App { M.appDraw = drawUi
|
|
|
|
, M.appStartEvent = return
|
|
|
|
, M.appHandleEvent = appEvent
|
2017-01-25 00:48:45 +03:00
|
|
|
, M.appAttrMap = const $ attrMap V.defAttr []
|
2015-07-10 23:20:05 +03:00
|
|
|
, M.appChooseCursor = M.neverShowCursor
|
|
|
|
}
|
2015-07-04 01:49:33 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2015-07-10 23:20:05 +03:00
|
|
|
main = void $ M.defaultMain app $ St (T.Location (0, 0)) (T.Location (0, 0))
|