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)
|
|
|
|
import Data.Default
|
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
|
2015-12-09 18:15:03 +03:00
|
|
|
import Brick.Types (rowL, columnL, 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
|
|
|
)
|
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 $
|
|
|
|
B.border $ str "This layer is centered but other\nlayers are visible underneath it."
|
|
|
|
, 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-03-05 01:42:49 +03:00
|
|
|
appEvent :: St -> V.Event -> T.EventM () (T.Next St)
|
2015-07-19 22:08:00 +03:00
|
|
|
appEvent st (V.EvKey V.KDown []) = M.continue $ st & topLayerLocation.rowL %~ (+ 1)
|
|
|
|
appEvent st (V.EvKey V.KUp []) = M.continue $ st & topLayerLocation.rowL %~ (subtract 1)
|
|
|
|
appEvent st (V.EvKey V.KRight []) = M.continue $ st & topLayerLocation.columnL %~ (+ 1)
|
|
|
|
appEvent st (V.EvKey V.KLeft []) = M.continue $ st & topLayerLocation.columnL %~ (subtract 1)
|
2015-07-04 02:04:23 +03:00
|
|
|
|
2015-07-19 22:08:00 +03:00
|
|
|
appEvent st (V.EvKey V.KDown [V.MCtrl]) = M.continue $ st & bottomLayerLocation.rowL %~ (+ 1)
|
|
|
|
appEvent st (V.EvKey V.KUp [V.MCtrl]) = M.continue $ st & bottomLayerLocation.rowL %~ (subtract 1)
|
|
|
|
appEvent st (V.EvKey V.KRight [V.MCtrl]) = M.continue $ st & bottomLayerLocation.columnL %~ (+ 1)
|
|
|
|
appEvent st (V.EvKey V.KLeft [V.MCtrl]) = M.continue $ st & bottomLayerLocation.columnL %~ (subtract 1)
|
2015-07-04 02:04:23 +03:00
|
|
|
|
2015-07-10 23:20:05 +03:00
|
|
|
appEvent st (V.EvKey V.KEsc []) = M.halt st
|
|
|
|
appEvent st _ = M.continue st
|
2015-07-04 01:49:33 +03:00
|
|
|
|
2016-03-05 01:42:49 +03:00
|
|
|
app :: M.App St V.Event ()
|
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
|
|
|
|
, M.appAttrMap = const def
|
2015-07-10 23:53:21 +03:00
|
|
|
, M.appLiftVtyEvent = id
|
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))
|