module Brick.Types.Internal
( ScrollRequest(..)
, VisibilityRequest(..)
, vrPositionL
, vrSizeL
, Location(..)
, locL
, origin
, TerminalLocation(..)
, Viewport(..)
, ViewportType(..)
, RenderState(..)
, Direction(..)
, CursorLocation(..)
, cursorLocationL
, cursorLocationNameL
, Context(..)
, EventState
, Next(..)
, scrollRequestsL
, viewportMapL
, observedNamesL
, vpSize
, vpLeft
, vpTop
)
where
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid
#endif
import Lens.Micro (_1, _2, Lens')
import Lens.Micro.TH (makeLenses)
import Lens.Micro.Internal (Field1, Field2)
import qualified Data.Set as S
import qualified Data.Map as M
import Graphics.Vty (DisplayRegion)
import Brick.Types.TH
import Brick.AttrMap (AttrName, AttrMap)
import Brick.Widgets.Border.Style (BorderStyle)
data RenderState n =
RS { viewportMap :: M.Map n Viewport
, scrollRequests :: [(n, ScrollRequest)]
, observedNames :: !(S.Set n)
}
data ScrollRequest = HScrollBy Int
| HScrollPage Direction
| HScrollToBeginning
| HScrollToEnd
| VScrollBy Int
| VScrollPage Direction
| VScrollToBeginning
| VScrollToEnd
data VisibilityRequest =
VR { vrPosition :: Location
, vrSize :: DisplayRegion
}
deriving (Show, Eq)
data Viewport =
VP { _vpLeft :: Int
, _vpTop :: Int
, _vpSize :: DisplayRegion
}
deriving Show
data ViewportType = Vertical
| Horizontal
| Both
deriving (Show, Eq)
type EventState n = [(n, ScrollRequest)]
data Next a = Continue a
| SuspendAndResume (IO a)
| Halt a
deriving Functor
data Direction = Up
| Down
deriving (Show, Eq)
data Location = Location { loc :: (Int, Int)
}
deriving (Show, Eq)
suffixLenses ''Location
instance Field1 Location Location Int Int where
_1 = locL._1
instance Field2 Location Location Int Int where
_2 = locL._2
class TerminalLocation a where
columnL :: Lens' a Int
column :: a -> Int
rowL :: Lens' a Int
row :: a -> Int
instance TerminalLocation Location where
columnL = _1
column (Location t) = fst t
rowL = _2
row (Location t) = snd t
origin :: Location
origin = Location (0, 0)
instance Monoid Location where
mempty = origin
mappend (Location (w1, h1)) (Location (w2, h2)) = Location (w1+w2, h1+h2)
data CursorLocation n =
CursorLocation { cursorLocation :: !Location
, cursorLocationName :: !(Maybe n)
}
deriving Show
data Context =
Context { ctxAttrName :: AttrName
, availWidth :: Int
, availHeight :: Int
, ctxBorderStyle :: BorderStyle
, ctxAttrMap :: AttrMap
}
deriving Show
suffixLenses ''RenderState
suffixLenses ''VisibilityRequest
suffixLenses ''CursorLocation
makeLenses ''Viewport