{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module Brick.Widgets.Core
(
TextWidth(..)
, emptyWidget
, raw
, txt
, txtWrap
, txtWrapWith
, str
, strWrap
, strWrapWith
, fill
, hyperlink
, Padding(..)
, padLeft
, padRight
, padTop
, padBottom
, padLeftRight
, padTopBottom
, padAll
, (<=>)
, (<+>)
, hBox
, vBox
, hLimit
, hLimitPercent
, vLimit
, vLimitPercent
, setAvailableSize
, withDefAttr
, modifyDefAttr
, withAttr
, forceAttr
, overrideAttr
, updateAttrMap
, withBorderStyle
, joinBorders
, separateBorders
, freezeBorders
, showCursor
, putCursor
, Named(..)
, translateBy
, relativeTo
, cropLeftBy
, cropRightBy
, cropTopBy
, cropBottomBy
, cropLeftTo
, cropRightTo
, cropTopTo
, cropBottomTo
, reportExtent
, clickable
, viewport
, visible
, visibleRegion
, unsafeLookupViewport
, cached
, withVScrollBars
, withHScrollBars
, withClickableHScrollBars
, withClickableVScrollBars
, withVScrollBarHandles
, withHScrollBarHandles
, withVScrollBarRenderer
, withHScrollBarRenderer
, ScrollbarRenderer(..)
, verticalScrollbarRenderer
, horizontalScrollbarRenderer
, scrollbarAttr
, scrollbarTroughAttr
, scrollbarHandleAttr
, verticalScrollbar
, horizontalScrollbar
, addResultOffset
, cropToContext
)
where
#if !(MIN_VERSION_base(4,11,0))
import Data.Monoid ((<>))
#endif
import Lens.Micro ((^.), (.~), (&), (%~), to, _1, _2, each, to, Lens')
import Lens.Micro.Mtl (use, (%=))
import Control.Monad.State.Strict
import Control.Monad.Reader
import qualified Data.Foldable as F
import Data.Traversable (for)
import qualified Data.Text as T
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.IMap as I
import qualified Data.Function as DF
import Data.List (sortBy, partition)
import Data.Maybe (fromMaybe)
import qualified Graphics.Vty as V
import Control.DeepSeq
import Text.Wrap (wrapTextToLines, WrapSettings, defaultWrapSettings)
import Brick.Types
import Brick.Types.Internal
import Brick.Widgets.Border.Style
import Brick.Util (clOffset, clamp)
import Brick.AttrMap
import Brick.Widgets.Internal
import qualified Brick.BorderMap as BM
class TextWidth a where
textWidth :: a -> Int
instance TextWidth T.Text where
textWidth :: Text -> Int
textWidth = String -> Int
V.wcswidth forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack
instance (F.Foldable f) => TextWidth (f Char) where
textWidth :: f Char -> Int
textWidth = String -> Int
V.wcswidth forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> [a]
F.toList
class Named a n where
getName :: a -> n
withBorderStyle :: BorderStyle -> Widget n -> Widget n
withBorderStyle :: forall n. BorderStyle -> Widget n -> Widget n
withBorderStyle BorderStyle
bs Widget n
p = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) BorderStyle
ctxBorderStyleL forall s t a b. ASetter s t a b -> b -> s -> t
.~ BorderStyle
bs) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
joinBorders :: Widget n -> Widget n
joinBorders :: forall n. Widget n -> Widget n
joinBorders Widget n
p = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Bool
ctxDynBordersL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
separateBorders :: Widget n -> Widget n
separateBorders :: forall n. Widget n -> Widget n
separateBorders Widget n
p = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Bool
ctxDynBordersL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
False) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
freezeBorders :: Widget n -> Widget n
freezeBorders :: forall n. Widget n -> Widget n
freezeBorders Widget n
p = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ (forall n. Lens' (Result n) (BorderMap DynBorder)
bordersL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall a b. BorderMap a -> BorderMap b
BM.clear) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n. Widget n -> RenderM n (Result n)
render Widget n
p
emptyWidget :: Widget n
emptyWidget :: forall n. Widget n
emptyWidget = forall n. Image -> Widget n
raw Image
V.emptyImage
addResultOffset :: Location -> Result n -> Result n
addResultOffset :: forall n. Location -> Result n -> Result n
addResultOffset Location
off = forall n. Location -> Result n -> Result n
addCursorOffset Location
off forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall n. Location -> Result n -> Result n
addVisibilityOffset Location
off forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall n. Location -> Result n -> Result n
addExtentOffset Location
off forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall n. Location -> Result n -> Result n
addDynBorderOffset Location
off
addVisibilityOffset :: Location -> Result n -> Result n
addVisibilityOffset :: forall n. Location -> Result n -> Result n
addVisibilityOffset Location
off Result n
r = Result n
r forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Each s t a b => Traversal s t a b
eachforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' VisibilityRequest Location
vrPositionL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Location
off forall a. Semigroup a => a -> a -> a
<>)
addExtentOffset :: Location -> Result n -> Result n
addExtentOffset :: forall n. Location -> Result n -> Result n
addExtentOffset Location
off Result n
r = Result n
r forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [Extent n]
extentsLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Each s t a b => Traversal s t a b
each forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\(Extent n
n Location
l DisplayRegion
sz) -> forall n. n -> Location -> DisplayRegion -> Extent n
Extent n
n (Location
off forall a. Semigroup a => a -> a -> a
<> Location
l) DisplayRegion
sz)
addDynBorderOffset :: Location -> Result n -> Result n
addDynBorderOffset :: forall n. Location -> Result n -> Result n
addDynBorderOffset Location
off Result n
r = Result n
r forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) (BorderMap DynBorder)
bordersL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall a. Location -> BorderMap a -> BorderMap a
BM.translate Location
off
reportExtent :: (Ord n) => n -> Widget n -> Widget n
reportExtent :: forall n. Ord n => n -> Widget n -> Widget n
reportExtent n
n Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let ext :: Extent n
ext = forall n. n -> Location -> DisplayRegion -> Extent n
Extent n
n (DisplayRegion -> Location
Location (Int
0, Int
0)) DisplayRegion
sz
sz :: DisplayRegion
sz = ( Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageWidth
, Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageHeight
)
Set n
vReqs <- forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use forall n. Lens' (RenderState n) (Set n)
requestedVisibleNames_L
let addVisReq :: Result n -> Result n
addVisReq = if DisplayRegion
szforall s a. s -> Getting a s a -> a
^.forall s t a b. Field1 s t a b => Lens s t a b
_1 forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& DisplayRegion
szforall s a. s -> Getting a s a -> a
^.forall s t a b. Field2 s t a b => Lens s t a b
_2 forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& n
n forall a. Ord a => a -> Set a -> Bool
`S.member` Set n
vReqs
then forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Location -> DisplayRegion -> VisibilityRequest
VR (DisplayRegion -> Location
Location (Int
0, Int
0)) DisplayRegion
sz forall a. a -> [a] -> [a]
:)
else forall a. a -> a
id
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Result n -> Result n
addVisReq forall a b. (a -> b) -> a -> b
$ Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [Extent n]
extentsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Extent n
extforall a. a -> [a] -> [a]
:)
clickable :: (Ord n) => n -> Widget n -> Widget n
clickable :: forall n. Ord n => n -> Widget n -> Widget n
clickable n
n Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
forall n. Lens' (RenderState n) [n]
clickableNamesL forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= (n
nforall a. a -> [a] -> [a]
:)
forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Ord n => n -> Widget n -> Widget n
reportExtent n
n Widget n
p
addCursorOffset :: Location -> Result n -> Result n
addCursorOffset :: forall n. Location -> Result n -> Result n
addCursorOffset Location
off Result n
r =
let onlyVisible :: [CursorLocation n] -> [CursorLocation n]
onlyVisible = forall a. (a -> Bool) -> [a] -> [a]
filter forall {s}. TerminalLocation s => s -> Bool
isVisible
isVisible :: s -> Bool
isVisible s
l = s
lforall s a. s -> Getting a s a -> a
^.forall a. TerminalLocation a => Lens' a Int
locationColumnL forall a. Ord a => a -> a -> Bool
>= Int
0 Bool -> Bool -> Bool
&& s
lforall s a. s -> Getting a s a -> a
^.forall a. TerminalLocation a => Lens' a Int
locationRowL forall a. Ord a => a -> a -> Bool
>= Int
0
in Result n
r forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [CursorLocation n]
cursorsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (\[CursorLocation n]
cs -> [CursorLocation n] -> [CursorLocation n]
onlyVisible forall a b. (a -> b) -> a -> b
$ (forall n. CursorLocation n -> Location -> CursorLocation n
`clOffset` Location
off) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [CursorLocation n]
cs)
unrestricted :: Int
unrestricted :: Int
unrestricted = Int
100000
strWrap :: String -> Widget n
strWrap :: forall n. String -> Widget n
strWrap = forall n. WrapSettings -> String -> Widget n
strWrapWith WrapSettings
defaultWrapSettings
strWrapWith :: WrapSettings -> String -> Widget n
strWrapWith :: forall n. WrapSettings -> String -> Widget n
strWrapWith WrapSettings
settings String
t = forall n. WrapSettings -> Text -> Widget n
txtWrapWith WrapSettings
settings forall a b. (a -> b) -> a -> b
$ String -> Text
T.pack String
t
txtWrap :: T.Text -> Widget n
txtWrap :: forall n. Text -> Widget n
txtWrap = forall n. WrapSettings -> Text -> Widget n
txtWrapWith WrapSettings
defaultWrapSettings
txtWrapWith :: WrapSettings -> T.Text -> Widget n
txtWrapWith :: forall n. WrapSettings -> Text -> Widget n
txtWrapWith WrapSettings
settings Text
s =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Fixed forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let theLines :: [Text]
theLines = Text -> Text
fixEmpty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WrapSettings -> Int -> Text -> [Text]
wrapTextToLines WrapSettings
settings (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL) Text
s
fixEmpty :: Text -> Text
fixEmpty Text
l | Text -> Bool
T.null Text
l = Text
" "
| Bool
otherwise = Text
l
case forall a. NFData a => a -> a
force [Text]
theLines of
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return forall n. Result n
emptyResult
[Text]
multiple ->
let maxLength :: Int
maxLength = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum forall a b. (a -> b) -> a -> b
$ forall a. TextWidth a => a -> Int
textWidth forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
multiple
padding :: Image
padding = forall d. Integral d => Attr -> Char -> d -> d -> Image
V.charFill (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL) Char
' ' (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL forall a. Num a => a -> a -> a
- Int
maxLength) (forall (t :: * -> *) a. Foldable t => t a -> Int
length [Image]
lineImgs)
lineImgs :: [Image]
lineImgs = Text -> Image
lineImg forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
multiple
lineImg :: Text -> Image
lineImg Text
lStr = Attr -> Text -> Image
V.text' (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL)
(Text
lStr forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
T.replicate (Int
maxLength forall a. Num a => a -> a -> a
- forall a. TextWidth a => a -> Int
textWidth Text
lStr) Text
" ")
in forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Result n
emptyResult forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> b -> s -> t
.~ ([Image] -> Image
V.horizCat [[Image] -> Image
V.vertCat [Image]
lineImgs, Image
padding])
str :: String -> Widget n
str :: forall n. String -> Widget n
str = forall n. Text -> Widget n
txt forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
txt :: T.Text -> Widget n
txt :: forall n. Text -> Widget n
txt Text
s =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let theLines :: [Text]
theLines = Text -> Text
fixEmpty forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ([Text] -> [Text]
dropUnused forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text]
T.lines) Text
s
fixEmpty :: Text -> Text
fixEmpty Text
l = if Text -> Bool
T.null Text
l then Char -> Text
T.singleton Char
' ' else Text
l
dropUnused :: [Text] -> [Text]
dropUnused [Text]
l = Int -> Text -> Text
takeColumnsT (forall n. Context n -> Int
availWidth Context n
c) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Int -> [a] -> [a]
take (forall n. Context n -> Int
availHeight Context n
c) [Text]
l
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case [Text]
theLines of
[] -> forall n. Result n
emptyResult
[Text
one] -> forall n. Result n
emptyResult forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Attr -> Text -> Image
V.text' (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL) Text
one)
[Text]
multiple ->
let maxLength :: Int
maxLength = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum forall a b. (a -> b) -> a -> b
$ Text -> Int
V.safeWctwidth forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
multiple
lineImgs :: [Image]
lineImgs = Text -> Image
lineImg forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Text]
multiple
lineImg :: Text -> Image
lineImg Text
lStr = Attr -> Text -> Image
V.text' (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL)
(Text
lStr forall a. Semigroup a => a -> a -> a
<> Int -> Text -> Text
T.replicate (Int
maxLength forall a. Num a => a -> a -> a
- Text -> Int
V.safeWctwidth Text
lStr) (Char -> Text
T.singleton Char
' '))
in forall n. Result n
emptyResult forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> b -> s -> t
.~ ([Image] -> Image
V.vertCat [Image]
lineImgs)
takeColumnsT :: Int -> T.Text -> T.Text
takeColumnsT :: Int -> Text -> Text
takeColumnsT Int
w Text
s = Int -> Text -> Text
T.take (forall a b. (a, b) -> a
fst forall a b. (a -> b) -> a -> b
$ forall a. (a -> Char -> a) -> a -> Text -> a
T.foldl' DisplayRegion -> Char -> DisplayRegion
f (Int
0,Int
0) Text
s) Text
s
where
f :: DisplayRegion -> Char -> DisplayRegion
f (Int
i,Int
z) Char
c
| Int
z forall a. Ord a => a -> a -> Bool
< Int
0 = (Int
i, Int
z)
| Int
z forall a. Num a => a -> a -> a
+ Char -> Int
V.safeWcwidth Char
c forall a. Ord a => a -> a -> Bool
> Int
w = (Int
i, -Int
1)
| Bool
otherwise = (Int
i forall a. Num a => a -> a -> a
+ Int
1, Int
z forall a. Num a => a -> a -> a
+ Char -> Int
V.safeWcwidth Char
c)
hyperlink :: T.Text -> Widget n -> Widget n
hyperlink :: forall n. Text -> Widget n -> Widget n
hyperlink Text
url Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let attr :: Attr
attr = (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL) Attr -> Text -> Attr
`V.withURL` Text
url
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) AttrMap
ctxAttrMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Attr -> AttrMap -> AttrMap
setDefaultAttr Attr
attr) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
data Padding = Pad Int
| Max
padLeft :: Padding -> Widget n -> Widget n
padLeft :: forall n. Padding -> Widget n -> Widget n
padLeft Padding
padding Widget n
p =
let (Widget n -> Widget n
f, Size
sz) = case Padding
padding of
Padding
Max -> (forall a. a -> a
id, Size
Greedy)
Pad Int
i -> (forall n. Int -> Widget n -> Widget n
hLimit Int
i, forall n. Widget n -> Size
hSize Widget n
p)
in forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
sz (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let lim :: Int
lim = case Padding
padding of
Padding
Max -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL
Pad Int
i -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL forall a. Num a => a -> a -> a
- Int
i
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit Int
lim Widget n
p
forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ (Widget n -> Widget n
f forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageHeight) forall a b. (a -> b) -> a -> b
$ forall n. Char -> Widget n
fill Char
' ') forall n. Widget n -> Widget n -> Widget n
<+>
(forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result)
padRight :: Padding -> Widget n -> Widget n
padRight :: forall n. Padding -> Widget n -> Widget n
padRight Padding
padding Widget n
p =
let (Widget n -> Widget n
f, Size
sz) = case Padding
padding of
Padding
Max -> (forall a. a -> a
id, Size
Greedy)
Pad Int
i -> (forall n. Int -> Widget n -> Widget n
hLimit Int
i, forall n. Widget n -> Size
hSize Widget n
p)
in forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
sz (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let lim :: Int
lim = case Padding
padding of
Padding
Max -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL
Pad Int
i -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL forall a. Num a => a -> a -> a
- Int
i
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit Int
lim Widget n
p
forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ (forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result) forall n. Widget n -> Widget n -> Widget n
<+>
(Widget n -> Widget n
f forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageHeight) forall a b. (a -> b) -> a -> b
$ forall n. Char -> Widget n
fill Char
' ')
padTop :: Padding -> Widget n -> Widget n
padTop :: forall n. Padding -> Widget n -> Widget n
padTop Padding
padding Widget n
p =
let (Widget n -> Widget n
f, Size
sz) = case Padding
padding of
Padding
Max -> (forall a. a -> a
id, Size
Greedy)
Pad Int
i -> (forall n. Int -> Widget n -> Widget n
vLimit Int
i, forall n. Widget n -> Size
vSize Widget n
p)
in forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) Size
sz forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let lim :: Int
lim = case Padding
padding of
Padding
Max -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL
Pad Int
i -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL forall a. Num a => a -> a -> a
- Int
i
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit Int
lim Widget n
p
forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ (Widget n -> Widget n
f forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageWidth) forall a b. (a -> b) -> a -> b
$ forall n. Char -> Widget n
fill Char
' ') forall n. Widget n -> Widget n -> Widget n
<=>
(forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result)
padBottom :: Padding -> Widget n -> Widget n
padBottom :: forall n. Padding -> Widget n -> Widget n
padBottom Padding
padding Widget n
p =
let (Widget n -> Widget n
f, Size
sz) = case Padding
padding of
Padding
Max -> (forall a. a -> a
id, Size
Greedy)
Pad Int
i -> (forall n. Int -> Widget n -> Widget n
vLimit Int
i, forall n. Widget n -> Size
vSize Widget n
p)
in forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) Size
sz forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let lim :: Int
lim = case Padding
padding of
Padding
Max -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL
Pad Int
i -> Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL forall a. Num a => a -> a -> a
- Int
i
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit Int
lim Widget n
p
forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ (forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result) forall n. Widget n -> Widget n -> Widget n
<=>
(Widget n -> Widget n
f forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageWidth) forall a b. (a -> b) -> a -> b
$ forall n. Char -> Widget n
fill Char
' ')
padLeftRight :: Int -> Widget n -> Widget n
padLeftRight :: forall n. Int -> Widget n -> Widget n
padLeftRight Int
c Widget n
w = forall n. Padding -> Widget n -> Widget n
padLeft (Int -> Padding
Pad Int
c) forall a b. (a -> b) -> a -> b
$ forall n. Padding -> Widget n -> Widget n
padRight (Int -> Padding
Pad Int
c) Widget n
w
padTopBottom :: Int -> Widget n -> Widget n
padTopBottom :: forall n. Int -> Widget n -> Widget n
padTopBottom Int
r Widget n
w = forall n. Padding -> Widget n -> Widget n
padTop (Int -> Padding
Pad Int
r) forall a b. (a -> b) -> a -> b
$ forall n. Padding -> Widget n -> Widget n
padBottom (Int -> Padding
Pad Int
r) Widget n
w
padAll :: Int -> Widget n -> Widget n
padAll :: forall n. Int -> Widget n -> Widget n
padAll Int
v Widget n
w = forall n. Int -> Widget n -> Widget n
padLeftRight Int
v forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
padTopBottom Int
v Widget n
w
fill :: Char -> Widget n
fill :: forall n. Char -> Widget n
fill Char
ch =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Greedy forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Result n
emptyResult forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> b -> s -> t
.~ (forall d. Integral d => Attr -> Char -> d -> d -> Image
V.charFill (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL) Char
ch (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL) (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL))
{-# NOINLINE vBox #-}
vBox :: [Widget n] -> Widget n
vBox :: forall n. [Widget n] -> Widget n
vBox [] = forall n. Widget n
emptyWidget
vBox [Widget n
a] = Widget n
a
vBox [Widget n]
pairs = forall n. BoxRenderer n -> [Widget n] -> Widget n
renderBox forall n. BoxRenderer n
vBoxRenderer [Widget n]
pairs
{-# NOINLINE hBox #-}
hBox :: [Widget n] -> Widget n
hBox :: forall n. [Widget n] -> Widget n
hBox [] = forall n. Widget n
emptyWidget
hBox [Widget n
a] = Widget n
a
hBox [Widget n]
pairs = forall n. BoxRenderer n -> [Widget n] -> Widget n
renderBox forall n. BoxRenderer n
hBoxRenderer [Widget n]
pairs
data BoxRenderer n =
BoxRenderer { forall n. BoxRenderer n -> Lens' (Context n) Int
contextPrimary :: Lens' (Context n) Int
, forall n. BoxRenderer n -> Lens' (Context n) Int
contextSecondary :: Lens' (Context n) Int
, forall n. BoxRenderer n -> Image -> Int
imagePrimary :: V.Image -> Int
, forall n. BoxRenderer n -> Image -> Int
imageSecondary :: V.Image -> Int
, forall n. BoxRenderer n -> Int -> Widget n -> Widget n
limitPrimary :: Int -> Widget n -> Widget n
, forall n. BoxRenderer n -> Widget n -> Size
primaryWidgetSize :: Widget n -> Size
, forall n. BoxRenderer n -> [Image] -> Image
concatenatePrimary :: [V.Image] -> V.Image
, forall n. BoxRenderer n -> [Image] -> Image
concatenateSecondary :: [V.Image] -> V.Image
, forall n. BoxRenderer n -> Int -> Location
locationFromOffset :: Int -> Location
, forall n. BoxRenderer n -> Int -> Image -> Attr -> Image
padImageSecondary :: Int -> V.Image -> V.Attr -> V.Image
, forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
loPrimary :: forall a. Lens' (Edges a) a
, forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
hiPrimary :: forall a. Lens' (Edges a) a
, forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
loSecondary :: forall a. Lens' (Edges a) a
, forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
hiSecondary :: forall a. Lens' (Edges a) a
, forall n. BoxRenderer n -> Int -> Int -> Location
locationFromPrimarySecondary :: Int -> Int -> Location
, forall n. BoxRenderer n -> Int -> Image -> Image
splitLoPrimary :: Int -> V.Image -> V.Image
, forall n. BoxRenderer n -> Int -> Image -> Image
splitHiPrimary :: Int -> V.Image -> V.Image
, forall n. BoxRenderer n -> Int -> Image -> Image
splitLoSecondary :: Int -> V.Image -> V.Image
, forall n. BoxRenderer n -> Int -> Image -> Image
splitHiSecondary :: Int -> V.Image -> V.Image
, forall n.
BoxRenderer n -> Int -> BorderMap DynBorder -> IMap DynBorder
lookupPrimary :: Int -> BM.BorderMap DynBorder -> I.IMap DynBorder
, forall n.
BoxRenderer n
-> Location
-> Run DynBorder
-> BorderMap DynBorder
-> BorderMap DynBorder
insertSecondary :: Location -> I.Run DynBorder -> BM.BorderMap DynBorder -> BM.BorderMap DynBorder
}
vBoxRenderer :: BoxRenderer n
vBoxRenderer :: forall n. BoxRenderer n
vBoxRenderer =
BoxRenderer { contextPrimary :: Lens' (Context n) Int
contextPrimary = forall n. Lens' (Context n) Int
availHeightL
, contextSecondary :: Lens' (Context n) Int
contextSecondary = forall n. Lens' (Context n) Int
availWidthL
, imagePrimary :: Image -> Int
imagePrimary = Image -> Int
V.imageHeight
, imageSecondary :: Image -> Int
imageSecondary = Image -> Int
V.imageWidth
, limitPrimary :: Int -> Widget n -> Widget n
limitPrimary = forall n. Int -> Widget n -> Widget n
vLimit
, primaryWidgetSize :: Widget n -> Size
primaryWidgetSize = forall n. Widget n -> Size
vSize
, concatenatePrimary :: [Image] -> Image
concatenatePrimary = [Image] -> Image
V.vertCat
, concatenateSecondary :: [Image] -> Image
concatenateSecondary = [Image] -> Image
V.horizCat
, locationFromOffset :: Int -> Location
locationFromOffset = DisplayRegion -> Location
Location forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int
0 ,)
, padImageSecondary :: Int -> Image -> Attr -> Image
padImageSecondary = \Int
amt Image
img Attr
a ->
let p :: Image
p = forall d. Integral d => Attr -> Char -> d -> d -> Image
V.charFill Attr
a Char
' ' Int
amt (Image -> Int
V.imageHeight Image
img)
in [Image] -> Image
V.horizCat [Image
img, Image
p]
, loPrimary :: forall a. Lens' (Edges a) a
loPrimary = forall a. Lens' (Edges a) a
eTopL
, hiPrimary :: forall a. Lens' (Edges a) a
hiPrimary = forall a. Lens' (Edges a) a
eBottomL
, loSecondary :: forall a. Lens' (Edges a) a
loSecondary = forall a. Lens' (Edges a) a
eLeftL
, hiSecondary :: forall a. Lens' (Edges a) a
hiSecondary = forall a. Lens' (Edges a) a
eRightL
, locationFromPrimarySecondary :: Int -> Int -> Location
locationFromPrimarySecondary = \Int
r Int
c -> DisplayRegion -> Location
Location (Int
c, Int
r)
, splitLoPrimary :: Int -> Image -> Image
splitLoPrimary = Int -> Image -> Image
V.cropBottom
, splitHiPrimary :: Int -> Image -> Image
splitHiPrimary = \Int
n Image
img -> Int -> Image -> Image
V.cropTop (Image -> Int
V.imageHeight Image
imgforall a. Num a => a -> a -> a
-Int
n) Image
img
, splitLoSecondary :: Int -> Image -> Image
splitLoSecondary = Int -> Image -> Image
V.cropRight
, splitHiSecondary :: Int -> Image -> Image
splitHiSecondary = \Int
n Image
img -> Int -> Image -> Image
V.cropLeft (Image -> Int
V.imageWidth Image
imgforall a. Num a => a -> a -> a
-Int
n) Image
img
, lookupPrimary :: Int -> BorderMap DynBorder -> IMap DynBorder
lookupPrimary = forall a. Int -> BorderMap a -> IMap a
BM.lookupRow
, insertSecondary :: Location
-> Run DynBorder -> BorderMap DynBorder -> BorderMap DynBorder
insertSecondary = forall a. Location -> Run a -> BorderMap a -> BorderMap a
BM.insertH
}
hBoxRenderer :: BoxRenderer n
hBoxRenderer :: forall n. BoxRenderer n
hBoxRenderer =
BoxRenderer { contextPrimary :: Lens' (Context n) Int
contextPrimary = forall n. Lens' (Context n) Int
availWidthL
, contextSecondary :: Lens' (Context n) Int
contextSecondary = forall n. Lens' (Context n) Int
availHeightL
, imagePrimary :: Image -> Int
imagePrimary = Image -> Int
V.imageWidth
, imageSecondary :: Image -> Int
imageSecondary = Image -> Int
V.imageHeight
, limitPrimary :: Int -> Widget n -> Widget n
limitPrimary = forall n. Int -> Widget n -> Widget n
hLimit
, primaryWidgetSize :: Widget n -> Size
primaryWidgetSize = forall n. Widget n -> Size
hSize
, concatenatePrimary :: [Image] -> Image
concatenatePrimary = [Image] -> Image
V.horizCat
, concatenateSecondary :: [Image] -> Image
concatenateSecondary = [Image] -> Image
V.vertCat
, locationFromOffset :: Int -> Location
locationFromOffset = DisplayRegion -> Location
Location forall b c a. (b -> c) -> (a -> b) -> a -> c
. (, Int
0)
, padImageSecondary :: Int -> Image -> Attr -> Image
padImageSecondary = \Int
amt Image
img Attr
a ->
let p :: Image
p = forall d. Integral d => Attr -> Char -> d -> d -> Image
V.charFill Attr
a Char
' ' (Image -> Int
V.imageWidth Image
img) Int
amt
in [Image] -> Image
V.vertCat [Image
img, Image
p]
, loPrimary :: forall a. Lens' (Edges a) a
loPrimary = forall a. Lens' (Edges a) a
eLeftL
, hiPrimary :: forall a. Lens' (Edges a) a
hiPrimary = forall a. Lens' (Edges a) a
eRightL
, loSecondary :: forall a. Lens' (Edges a) a
loSecondary = forall a. Lens' (Edges a) a
eTopL
, hiSecondary :: forall a. Lens' (Edges a) a
hiSecondary = forall a. Lens' (Edges a) a
eBottomL
, locationFromPrimarySecondary :: Int -> Int -> Location
locationFromPrimarySecondary = \Int
c Int
r -> DisplayRegion -> Location
Location (Int
c, Int
r)
, splitLoPrimary :: Int -> Image -> Image
splitLoPrimary = Int -> Image -> Image
V.cropRight
, splitHiPrimary :: Int -> Image -> Image
splitHiPrimary = \Int
n Image
img -> Int -> Image -> Image
V.cropLeft (Image -> Int
V.imageWidth Image
imgforall a. Num a => a -> a -> a
-Int
n) Image
img
, splitLoSecondary :: Int -> Image -> Image
splitLoSecondary = Int -> Image -> Image
V.cropBottom
, splitHiSecondary :: Int -> Image -> Image
splitHiSecondary = \Int
n Image
img -> Int -> Image -> Image
V.cropTop (Image -> Int
V.imageHeight Image
imgforall a. Num a => a -> a -> a
-Int
n) Image
img
, lookupPrimary :: Int -> BorderMap DynBorder -> IMap DynBorder
lookupPrimary = forall a. Int -> BorderMap a -> IMap a
BM.lookupCol
, insertSecondary :: Location
-> Run DynBorder -> BorderMap DynBorder -> BorderMap DynBorder
insertSecondary = forall a. Location -> Run a -> BorderMap a -> BorderMap a
BM.insertV
}
renderBox :: BoxRenderer n -> [Widget n] -> Widget n
renderBox :: forall n. BoxRenderer n -> [Widget n] -> Widget n
renderBox BoxRenderer n
br [Widget n]
ws =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Size
hSize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Widget n]
ws) (forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Size
vSize forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Widget n]
ws) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let pairsIndexed :: [(Int, Widget n)]
pairsIndexed = forall a b. [a] -> [b] -> [(a, b)]
zip [(Int
0::Int)..] [Widget n]
ws
([(Int, Widget n)]
his, [(Int, Widget n)]
lows) = forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (\(Int, Widget n)
p -> (forall n. BoxRenderer n -> Widget n -> Size
primaryWidgetSize BoxRenderer n
br forall a b. (a -> b) -> a -> b
$ forall a b. (a, b) -> b
snd (Int, Widget n)
p) forall a. Eq a => a -> a -> Bool
== Size
Fixed)
[(Int, Widget n)]
pairsIndexed
renderHi :: Widget n
-> StateT
Int (ReaderT (Context n) (State (RenderState n))) (Result n)
renderHi Widget n
prim = do
Int
remainingPrimary <- forall s (m :: * -> *). MonadState s m => m s
get
Result n
result <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. BoxRenderer n -> Int -> Widget n -> Widget n
limitPrimary BoxRenderer n
br Int
remainingPrimary Widget n
prim
Result n
result forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ (forall s (m :: * -> *). MonadState s m => s -> m ()
put forall a b. (a -> b) -> a -> b
$! Int
remainingPrimary forall a. Num a => a -> a -> a
- (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.(forall s a. (s -> a) -> SimpleGetter s a
to forall a b. (a -> b) -> a -> b
$ forall n. BoxRenderer n -> Image -> Int
imagePrimary BoxRenderer n
br)))
([(Int, Result n)]
renderedHis, Int
remainingPrimary) <-
forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse Widget n
-> StateT
Int (ReaderT (Context n) (State (RenderState n))) (Result n)
renderHi) [(Int, Widget n)]
his) (Context n
c forall s a. s -> Getting a s a -> a
^. forall n. BoxRenderer n -> Lens' (Context n) Int
contextPrimary BoxRenderer n
br)
[(Int, Result n)]
renderedLows <- case [(Int, Widget n)]
lows of
[] -> forall (m :: * -> *) a. Monad m => a -> m a
return []
[(Int, Widget n)]
ls -> do
let primaryPerLow :: Int
primaryPerLow = Int
remainingPrimary forall a. Integral a => a -> a -> a
`div` forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Int, Widget n)]
ls
rest :: Int
rest = Int
remainingPrimary forall a. Num a => a -> a -> a
- (Int
primaryPerLow forall a. Num a => a -> a -> a
* forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Int, Widget n)]
ls)
primaries :: [Int]
primaries = forall a. Int -> a -> [a]
replicate Int
rest (Int
primaryPerLow forall a. Num a => a -> a -> a
+ Int
1) forall a. Semigroup a => a -> a -> a
<>
forall a. Int -> a -> [a]
replicate (forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Int, Widget n)]
ls forall a. Num a => a -> a -> a
- Int
rest) Int
primaryPerLow
let renderLow :: ((Int, Widget n), Int)
-> ReaderT (Context n) (State (RenderState n)) (Int, Result n)
renderLow ((Int
i, Widget n
prim), Int
pri) = (Int
i,) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall n. Widget n -> RenderM n (Result n)
render (forall n. BoxRenderer n -> Int -> Widget n -> Widget n
limitPrimary BoxRenderer n
br Int
pri Widget n
prim)
if Int
remainingPrimary forall a. Ord a => a -> a -> Bool
> Int
0 then forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ((Int, Widget n), Int)
-> ReaderT (Context n) (State (RenderState n)) (Int, Result n)
renderLow (forall a b. [a] -> [b] -> [(a, b)]
zip [(Int, Widget n)]
ls [Int]
primaries) else forall (m :: * -> *) a. Monad m => a -> m a
return []
let rendered :: [(Int, Result n)]
rendered = forall a. (a -> a -> Ordering) -> [a] -> [a]
sortBy (forall a. Ord a => a -> a -> Ordering
compare forall b c a. (b -> b -> c) -> (a -> b) -> a -> a -> c
`DF.on` forall a b. (a, b) -> a
fst) forall a b. (a -> b) -> a -> b
$ [(Int, Result n)]
renderedHis forall a. [a] -> [a] -> [a]
++ [(Int, Result n)]
renderedLows
allResults :: [Result n]
allResults = forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(Int, Result n)]
rendered
allImages :: [Image]
allImages = (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Result n]
allResults
allTranslatedResults :: [Result n]
allTranslatedResults = forall a b c. (a -> b -> c) -> b -> a -> c
flip forall s a. State s a -> s -> a
evalState Int
0 forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
t a -> (a -> f b) -> f (t b)
for [Result n]
allResults forall a b. (a -> b) -> a -> b
$ \Result n
result -> do
Int
offPrimary <- forall s (m :: * -> *). MonadState s m => m s
get
forall s (m :: * -> *). MonadState s m => s -> m ()
put forall a b. (a -> b) -> a -> b
$ Int
offPrimary forall a. Num a => a -> a -> a
+ (Result n
result forall s a. s -> Getting a s a -> a
^. forall n. Lens' (Result n) Image
imageL forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s a. (s -> a) -> SimpleGetter s a
to (forall n. BoxRenderer n -> Image -> Int
imagePrimary BoxRenderer n
br))
forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall n. Location -> Result n -> Result n
addResultOffset (forall n. BoxRenderer n -> Int -> Location
locationFromOffset BoxRenderer n
br Int
offPrimary) Result n
result
maxSecondary :: Int
maxSecondary = forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum forall a b. (a -> b) -> a -> b
$ forall n. BoxRenderer n -> Image -> Int
imageSecondary BoxRenderer n
br forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Image]
allImages
padImage :: Image -> Image
padImage Image
img = forall n. BoxRenderer n -> Int -> Image -> Attr -> Image
padImageSecondary BoxRenderer n
br (Int
maxSecondary forall a. Num a => a -> a -> a
- forall n. BoxRenderer n -> Image -> Int
imageSecondary BoxRenderer n
br Image
img)
Image
img (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL)
([(IMap Image, IMap Image)]
imageRewrites, BorderMap DynBorder
newBorders) = forall n.
BoxRenderer n
-> [BorderMap DynBorder]
-> ([(IMap Image, IMap Image)], BorderMap DynBorder)
catAllBorders BoxRenderer n
br (forall n. Result n -> BorderMap DynBorder
borders forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Result n]
allTranslatedResults)
rewrittenImages :: [Image]
rewrittenImages = forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (forall n.
BoxRenderer n -> (IMap Image, IMap Image) -> Image -> Image
rewriteImage BoxRenderer n
br) [(IMap Image, IMap Image)]
imageRewrites [Image]
allImages
paddedImages :: [Image]
paddedImages = Image -> Image
padImage forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Image]
rewrittenImages
forall n. Result n -> RenderM n (Result n)
cropResultToContext forall a b. (a -> b) -> a -> b
$ forall n.
Image
-> [CursorLocation n]
-> [VisibilityRequest]
-> [Extent n]
-> BorderMap DynBorder
-> Result n
Result (forall n. BoxRenderer n -> [Image] -> Image
concatenatePrimary BoxRenderer n
br [Image]
paddedImages)
(forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall n. Result n -> [CursorLocation n]
cursors [Result n]
allTranslatedResults)
(forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall n. Result n -> [VisibilityRequest]
visibilityRequests [Result n]
allTranslatedResults)
(forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap forall n. Result n -> [Extent n]
extents [Result n]
allTranslatedResults)
BorderMap DynBorder
newBorders
catDynBorder
:: Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> DynBorder
-> DynBorder
-> Maybe DynBorder
catDynBorder :: Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> DynBorder
-> DynBorder
-> Maybe DynBorder
catDynBorder Lens' (Edges BorderSegment) BorderSegment
towardsA Lens' (Edges BorderSegment) BorderSegment
towardsB DynBorder
a DynBorder
b
| DynBorder -> BorderStyle
dbStyle DynBorder
a forall a. Eq a => a -> a -> Bool
== DynBorder -> BorderStyle
dbStyle DynBorder
b
Bool -> Bool -> Bool
&& DynBorder -> Attr
dbAttr DynBorder
a forall a. Eq a => a -> a -> Bool
== DynBorder -> Attr
dbAttr DynBorder
b
Bool -> Bool -> Bool
&& DynBorder
a forall s a. s -> Getting a s a -> a
^. Lens' DynBorder (Edges BorderSegment)
dbSegmentsLforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' (Edges BorderSegment) BorderSegment
towardsBforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' BorderSegment Bool
bsAcceptL
Bool -> Bool -> Bool
&& DynBorder
b forall s a. s -> Getting a s a -> a
^. Lens' DynBorder (Edges BorderSegment)
dbSegmentsLforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' (Edges BorderSegment) BorderSegment
towardsAforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' BorderSegment Bool
bsOfferL
Bool -> Bool -> Bool
&& Bool -> Bool
not (DynBorder
a forall s a. s -> Getting a s a -> a
^. Lens' DynBorder (Edges BorderSegment)
dbSegmentsLforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' (Edges BorderSegment) BorderSegment
towardsBforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' BorderSegment Bool
bsDrawL)
= forall a. a -> Maybe a
Just (DynBorder
a forall a b. a -> (a -> b) -> b
& Lens' DynBorder (Edges BorderSegment)
dbSegmentsLforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' (Edges BorderSegment) BorderSegment
towardsBforall b c a. (b -> c) -> (a -> b) -> a -> c
.Lens' BorderSegment Bool
bsDrawL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True)
| Bool
otherwise = forall a. Maybe a
Nothing
catDynBorders
:: Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> I.IMap DynBorder
-> I.IMap DynBorder
-> I.IMap DynBorder
catDynBorders :: Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> IMap DynBorder
-> IMap DynBorder
-> IMap DynBorder
catDynBorders Lens' (Edges BorderSegment) BorderSegment
towardsA Lens' (Edges BorderSegment) BorderSegment
towardsB IMap DynBorder
am IMap DynBorder
bm = forall a b. (a -> Maybe b) -> IMap a -> IMap b
I.mapMaybe forall a. a -> a
id
forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> IMap a -> IMap b -> IMap c
I.intersectionWith (Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> DynBorder
-> DynBorder
-> Maybe DynBorder
catDynBorder Lens' (Edges BorderSegment) BorderSegment
towardsA Lens' (Edges BorderSegment) BorderSegment
towardsB) IMap DynBorder
am IMap DynBorder
bm
catBorders
:: (border ~ BM.BorderMap DynBorder, rewrite ~ I.IMap V.Image)
=> BoxRenderer n -> border -> border -> ((rewrite, rewrite), border)
catBorders :: forall border rewrite n.
(border ~ BorderMap DynBorder, rewrite ~ IMap Image) =>
BoxRenderer n -> border -> border -> ((rewrite, rewrite), border)
catBorders BoxRenderer n
br border
r border
l = if Int
lCoord forall a. Num a => a -> a -> a
+ Int
1 forall a. Eq a => a -> a -> Bool
== Int
rCoord
then ((IMap Image
lRe, IMap Image
rRe), BorderMap DynBorder
lr')
else ((forall a. IMap a
I.empty, forall a. IMap a
I.empty), BorderMap DynBorder
lr)
where
lr :: BorderMap DynBorder
lr = forall a. Edges Int -> BorderMap a -> BorderMap a
BM.expand (forall a. BorderMap a -> Edges Int
BM.coordinates border
r) border
l forall a. BorderMap a -> BorderMap a -> BorderMap a
`BM.unsafeUnion`
forall a. Edges Int -> BorderMap a -> BorderMap a
BM.expand (forall a. BorderMap a -> Edges Int
BM.coordinates border
l) border
r
lr' :: BorderMap DynBorder
lr' = forall a. a -> a
id
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IMap DynBorder -> BorderMap DynBorder -> BorderMap DynBorder
mergeIMap Int
lCoord IMap DynBorder
lIMap'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> IMap DynBorder -> BorderMap DynBorder -> BorderMap DynBorder
mergeIMap Int
rCoord IMap DynBorder
rIMap'
forall a b. (a -> b) -> a -> b
$ BorderMap DynBorder
lr
lCoord :: Int
lCoord = forall a. BorderMap a -> Edges Int
BM.coordinates border
l forall s a. s -> Getting a s a -> a
^. forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
hiPrimary BoxRenderer n
br
rCoord :: Int
rCoord = forall a. BorderMap a -> Edges Int
BM.coordinates border
r forall s a. s -> Getting a s a -> a
^. forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
loPrimary BoxRenderer n
br
lIMap :: IMap DynBorder
lIMap = forall n.
BoxRenderer n -> Int -> BorderMap DynBorder -> IMap DynBorder
lookupPrimary BoxRenderer n
br Int
lCoord border
l
rIMap :: IMap DynBorder
rIMap = forall n.
BoxRenderer n -> Int -> BorderMap DynBorder -> IMap DynBorder
lookupPrimary BoxRenderer n
br Int
rCoord border
r
lIMap' :: IMap DynBorder
lIMap' = Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> IMap DynBorder
-> IMap DynBorder
-> IMap DynBorder
catDynBorders (forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
loPrimary BoxRenderer n
br) (forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
hiPrimary BoxRenderer n
br) IMap DynBorder
lIMap IMap DynBorder
rIMap
rIMap' :: IMap DynBorder
rIMap' = Lens' (Edges BorderSegment) BorderSegment
-> Lens' (Edges BorderSegment) BorderSegment
-> IMap DynBorder
-> IMap DynBorder
-> IMap DynBorder
catDynBorders (forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
hiPrimary BoxRenderer n
br) (forall n. BoxRenderer n -> forall a. Lens' (Edges a) a
loPrimary BoxRenderer n
br) IMap DynBorder
rIMap IMap DynBorder
lIMap
lRe :: IMap Image
lRe = DynBorder -> Image
renderDynBorder forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IMap DynBorder
lIMap'
rRe :: IMap Image
rRe = DynBorder -> Image
renderDynBorder forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IMap DynBorder
rIMap'
mergeIMap :: Int -> IMap DynBorder -> BorderMap DynBorder -> BorderMap DynBorder
mergeIMap Int
p IMap DynBorder
imap BorderMap DynBorder
bm = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
F.foldl'
(\BorderMap DynBorder
bm' (Int
s,Run DynBorder
v) -> forall n.
BoxRenderer n
-> Location
-> Run DynBorder
-> BorderMap DynBorder
-> BorderMap DynBorder
insertSecondary BoxRenderer n
br (forall n. BoxRenderer n -> Int -> Int -> Location
locationFromPrimarySecondary BoxRenderer n
br Int
p Int
s) Run DynBorder
v BorderMap DynBorder
bm')
BorderMap DynBorder
bm
(forall a. IMap a -> [(Int, Run a)]
I.unsafeToAscList IMap DynBorder
imap)
catAllBorders ::
BoxRenderer n ->
[BM.BorderMap DynBorder] ->
([(I.IMap V.Image, I.IMap V.Image)], BM.BorderMap DynBorder)
catAllBorders :: forall n.
BoxRenderer n
-> [BorderMap DynBorder]
-> ([(IMap Image, IMap Image)], BorderMap DynBorder)
catAllBorders BoxRenderer n
_ [] = ([], forall a. BorderMap a
BM.empty)
catAllBorders BoxRenderer n
br (BorderMap DynBorder
bm:[BorderMap DynBorder]
bms) = (forall a b. [a] -> [b] -> [(a, b)]
zip ([forall a. IMap a
I.empty]forall a. [a] -> [a] -> [a]
++[IMap Image]
los) ([IMap Image]
hisforall a. [a] -> [a] -> [a]
++[forall a. IMap a
I.empty]), BorderMap DynBorder
bm') where
([(IMap Image, IMap Image)]
rewrites, BorderMap DynBorder
bm') = forall s a. State s a -> s -> (a, s)
runState (forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse (forall s (m :: * -> *) a. MonadState s m => (s -> (a, s)) -> m a
state forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall border rewrite n.
(border ~ BorderMap DynBorder, rewrite ~ IMap Image) =>
BoxRenderer n -> border -> border -> ((rewrite, rewrite), border)
catBorders BoxRenderer n
br) [BorderMap DynBorder]
bms) BorderMap DynBorder
bm
([IMap Image]
his, [IMap Image]
los) = forall a b. [(a, b)] -> ([a], [b])
unzip [(IMap Image, IMap Image)]
rewrites
rewriteEdge ::
(Int -> V.Image -> V.Image) ->
(Int -> V.Image -> V.Image) ->
([V.Image] -> V.Image) ->
I.IMap V.Image -> V.Image -> V.Image
rewriteEdge :: (Int -> Image -> Image)
-> (Int -> Image -> Image)
-> ([Image] -> Image)
-> IMap Image
-> Image
-> Image
rewriteEdge Int -> Image -> Image
splitLo Int -> Image -> Image
splitHi [Image] -> Image
combine = ([Image] -> Image
combine forall b c a. (b -> c) -> (a -> b) -> a -> c
.) forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Int, Run Image)] -> Image -> [Image]
go forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {a}. Int -> [(Int, Run a)] -> [(Int, Run a)]
offsets Int
0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IMap a -> [(Int, Run a)]
I.unsafeToAscList where
offsets :: Int -> [(Int, Run a)] -> [(Int, Run a)]
offsets Int
_ [] = []
offsets Int
n ((Int
n', Run a
r):[(Int, Run a)]
nrs) = (Int
n'forall a. Num a => a -> a -> a
-Int
n, Run a
r) forall a. a -> [a] -> [a]
: Int -> [(Int, Run a)] -> [(Int, Run a)]
offsets (Int
n'forall a. Num a => a -> a -> a
+forall a. Run a -> Int
I.len Run a
r) [(Int, Run a)]
nrs
go :: [(Int, Run Image)] -> Image -> [Image]
go [] Image
old = [Image
old]
go ((Int
lo, I.Run Int
len Image
new):[(Int, Run Image)]
nrs) Image
old
= [Int -> Image -> Image
splitLo Int
lo Image
old]
forall a. [a] -> [a] -> [a]
++ forall a. Int -> a -> [a]
replicate Int
len Image
new
forall a. [a] -> [a] -> [a]
++ [(Int, Run Image)] -> Image -> [Image]
go [(Int, Run Image)]
nrs (Int -> Image -> Image
splitHi (Int
loforall a. Num a => a -> a -> a
+Int
len) Image
old)
rewriteImage :: BoxRenderer n -> (I.IMap V.Image, I.IMap V.Image) -> V.Image -> V.Image
rewriteImage :: forall n.
BoxRenderer n -> (IMap Image, IMap Image) -> Image -> Image
rewriteImage BoxRenderer n
br (IMap Image
loRewrite, IMap Image
hiRewrite) Image
old = Image -> Image
rewriteHi forall b c a. (b -> c) -> (a -> b) -> a -> c
. Image -> Image
rewriteLo forall a b. (a -> b) -> a -> b
$ Image
old where
size :: Int
size = forall n. BoxRenderer n -> Image -> Int
imagePrimary BoxRenderer n
br Image
old
go :: IMap Image -> Image -> Image
go = (Int -> Image -> Image)
-> (Int -> Image -> Image)
-> ([Image] -> Image)
-> IMap Image
-> Image
-> Image
rewriteEdge (forall n. BoxRenderer n -> Int -> Image -> Image
splitLoSecondary BoxRenderer n
br) (forall n. BoxRenderer n -> Int -> Image -> Image
splitHiSecondary BoxRenderer n
br) (forall n. BoxRenderer n -> [Image] -> Image
concatenateSecondary BoxRenderer n
br)
rewriteLo :: Image -> Image
rewriteLo Image
img
| forall a. IMap a -> Bool
I.null IMap Image
loRewrite Bool -> Bool -> Bool
|| Int
size forall a. Eq a => a -> a -> Bool
== Int
0 = Image
img
| Bool
otherwise = forall n. BoxRenderer n -> [Image] -> Image
concatenatePrimary BoxRenderer n
br
[ IMap Image -> Image -> Image
go IMap Image
loRewrite (forall n. BoxRenderer n -> Int -> Image -> Image
splitLoPrimary BoxRenderer n
br Int
1 Image
img)
, forall n. BoxRenderer n -> Int -> Image -> Image
splitHiPrimary BoxRenderer n
br Int
1 Image
img
]
rewriteHi :: Image -> Image
rewriteHi Image
img
| forall a. IMap a -> Bool
I.null IMap Image
hiRewrite Bool -> Bool -> Bool
|| Int
size forall a. Eq a => a -> a -> Bool
== Int
0 = Image
img
| Bool
otherwise = forall n. BoxRenderer n -> [Image] -> Image
concatenatePrimary BoxRenderer n
br
[ forall n. BoxRenderer n -> Int -> Image -> Image
splitLoPrimary BoxRenderer n
br (Int
sizeforall a. Num a => a -> a -> a
-Int
1) Image
img
, IMap Image -> Image -> Image
go IMap Image
hiRewrite (forall n. BoxRenderer n -> Int -> Image -> Image
splitHiPrimary BoxRenderer n
br (Int
sizeforall a. Num a => a -> a -> a
-Int
1) Image
img)
]
hLimit :: Int -> Widget n -> Widget n
hLimit :: forall n. Int -> Widget n -> Widget n
hLimit Int
w Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Int
availWidthL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall a. Ord a => a -> a -> a
min Int
w)) forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Widget n
cropToContext Widget n
p
hLimitPercent :: Int -> Widget n -> Widget n
hLimitPercent :: forall n. Int -> Widget n -> Widget n
hLimitPercent Int
w' Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
let w :: Int
w = forall a. Ord a => a -> a -> a -> a
clamp Int
0 Int
100 Int
w'
Context n
ctx <- forall n. RenderM n (Context n)
getContext
let usableWidth :: Int
usableWidth = Context n
ctxforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL
widgetWidth :: Int
widgetWidth = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a. Real a => a -> Rational
toRational Int
usableWidth forall a. Num a => a -> a -> a
* (forall a. Real a => a -> Rational
toRational Int
w forall a. Fractional a => a -> a -> a
/ Rational
100))
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Int
availWidthL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall a. Ord a => a -> a -> a
min Int
widgetWidth)) forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Widget n
cropToContext Widget n
p
vLimit :: Int -> Widget n -> Widget n
vLimit :: forall n. Int -> Widget n -> Widget n
vLimit Int
h Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) Size
Fixed forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Int
availHeightL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall a. Ord a => a -> a -> a
min Int
h)) forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Widget n
cropToContext Widget n
p
vLimitPercent :: Int -> Widget n -> Widget n
vLimitPercent :: forall n. Int -> Widget n -> Widget n
vLimitPercent Int
h' Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) Size
Fixed forall a b. (a -> b) -> a -> b
$ do
let h :: Int
h = forall a. Ord a => a -> a -> a -> a
clamp Int
0 Int
100 Int
h'
Context n
ctx <- forall n. RenderM n (Context n)
getContext
let usableHeight :: Int
usableHeight = Context n
ctxforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL
widgetHeight :: Int
widgetHeight = forall a b. (RealFrac a, Integral b) => a -> b
round (forall a. Real a => a -> Rational
toRational Int
usableHeight forall a. Num a => a -> a -> a
* (forall a. Real a => a -> Rational
toRational Int
h forall a. Fractional a => a -> a -> a
/ Rational
100))
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Int
availHeightL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall a. Ord a => a -> a -> a
min Int
widgetHeight)) forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Widget n
cropToContext Widget n
p
setAvailableSize :: (Int, Int) -> Widget n -> Widget n
setAvailableSize :: forall n. DisplayRegion -> Widget n -> Widget n
setAvailableSize (Int
w, Int
h) Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (\Context n
c -> Context n
c forall a b. a -> (a -> b) -> b
& forall n. Lens' (Context n) Int
availHeightL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
h forall a b. a -> (a -> b) -> b
& forall n. Lens' (Context n) Int
availWidthL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
w) forall a b. (a -> b) -> a -> b
$
forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Widget n -> Widget n
cropToContext Widget n
p
withAttr :: AttrName -> Widget n -> Widget n
withAttr :: forall n. AttrName -> Widget n -> Widget n
withAttr AttrName
an Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) AttrName
ctxAttrNameL forall s t a b. ASetter s t a b -> b -> s -> t
.~ AttrName
an) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
modifyDefAttr :: (V.Attr -> V.Attr) -> Widget n -> Widget n
modifyDefAttr :: forall n. (Attr -> Attr) -> Widget n -> Widget n
modifyDefAttr Attr -> Attr
f Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) AttrMap
ctxAttrMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Attr -> AttrMap -> AttrMap
setDefaultAttr (Attr -> Attr
f forall a b. (a -> b) -> a -> b
$ AttrMap -> Attr
getDefaultAttr (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) AttrMap
ctxAttrMapL)))) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
withDefAttr :: AttrName -> Widget n -> Widget n
withDefAttr :: forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
an Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) AttrMap
ctxAttrMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Attr -> AttrMap -> AttrMap
setDefaultAttr (AttrName -> AttrMap -> Attr
attrMapLookup AttrName
an (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) AttrMap
ctxAttrMapL)))) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
updateAttrMap :: (AttrMap -> AttrMap) -> Widget n -> Widget n
updateAttrMap :: forall n. (AttrMap -> AttrMap) -> Widget n -> Widget n
updateAttrMap AttrMap -> AttrMap
f Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) AttrMap
ctxAttrMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ AttrMap -> AttrMap
f) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
forceAttr :: AttrName -> Widget n -> Widget n
forceAttr :: forall n. AttrName -> Widget n -> Widget n
forceAttr AttrName
an Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) AttrMap
ctxAttrMapL forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Attr -> AttrMap
forceAttrMap (AttrName -> AttrMap -> Attr
attrMapLookup AttrName
an (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) AttrMap
ctxAttrMapL)))) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
overrideAttr :: AttrName -> AttrName -> Widget n -> Widget n
overrideAttr :: forall n. AttrName -> AttrName -> Widget n -> Widget n
overrideAttr AttrName
targetName AttrName
fromName =
forall n. (AttrMap -> AttrMap) -> Widget n -> Widget n
updateAttrMap (AttrName -> AttrName -> AttrMap -> AttrMap
mapAttrName AttrName
fromName AttrName
targetName)
raw :: V.Image -> Widget n
raw :: forall n. Image -> Widget n
raw Image
img = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Result n
emptyResult forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
img
translateBy :: Location -> Widget n -> Widget n
translateBy :: forall n. Location -> Widget n -> Widget n
translateBy Location
off Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Location -> Result n -> Result n
addResultOffset Location
off
forall a b. (a -> b) -> a -> b
$ Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Int -> Int -> Image -> Image
V.translate (Location
offforall s a. s -> Getting a s a -> a
^.forall a. TerminalLocation a => Lens' a Int
locationColumnL) (Location
offforall s a. s -> Getting a s a -> a
^.forall a. TerminalLocation a => Lens' a Int
locationRowL))
relativeTo :: (Ord n) => n -> Location -> Widget n -> Widget n
relativeTo :: forall n. Ord n => n -> Location -> Widget n -> Widget n
relativeTo n
n Location
off Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$ do
Maybe (Extent n)
mExt <- forall n. Ord n => n -> RenderM n (Maybe (Extent n))
lookupReportedExtent n
n
case Maybe (Extent n)
mExt of
Maybe (Extent n)
Nothing -> forall n. Widget n -> RenderM n (Result n)
render Widget n
w
Just Extent n
ext -> forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Location -> Widget n -> Widget n
translateBy (forall n. Extent n -> Location
extentUpperLeft Extent n
ext forall a. Semigroup a => a -> a -> a
<> Location
off) Widget n
w
cropLeftBy :: Int -> Widget n -> Widget n
cropLeftBy :: forall n. Int -> Widget n -> Widget n
cropLeftBy Int
cols Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let amt :: Int
amt = Image -> Int
V.imageWidth (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a. Num a => a -> a -> a
- Int
cols
cropped :: Image -> Image
cropped Image
img = if Int
amt forall a. Ord a => a -> a -> Bool
< Int
0 then Image
V.emptyImage else Int -> Image -> Image
V.cropLeft Int
amt Image
img
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Location -> Result n -> Result n
addResultOffset (DisplayRegion -> Location
Location (-Int
1 forall a. Num a => a -> a -> a
* Int
cols, Int
0))
forall a b. (a -> b) -> a -> b
$ Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Image -> Image
cropped
cropLeftTo :: Int -> Widget n -> Widget n
cropLeftTo :: forall n. Int -> Widget n -> Widget n
cropLeftTo Int
cols Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let w :: Int
w = Image -> Int
V.imageWidth forall a b. (a -> b) -> a -> b
$ Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL
amt :: Int
amt = Int
w forall a. Num a => a -> a -> a
- Int
cols
if Int
w forall a. Ord a => a -> a -> Bool
<= Int
cols
then forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
else forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
cropLeftBy Int
amt forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
cropRightBy :: Int -> Widget n -> Widget n
cropRightBy :: forall n. Int -> Widget n -> Widget n
cropRightBy Int
cols Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let amt :: Int
amt = Image -> Int
V.imageWidth (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a. Num a => a -> a -> a
- Int
cols
cropped :: Image -> Image
cropped Image
img = if Int
amt forall a. Ord a => a -> a -> Bool
< Int
0 then Image
V.emptyImage else Int -> Image -> Image
V.cropRight Int
amt Image
img
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Image -> Image
cropped
cropRightTo :: Int -> Widget n -> Widget n
cropRightTo :: forall n. Int -> Widget n -> Widget n
cropRightTo Int
cols Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let w :: Int
w = Image -> Int
V.imageWidth forall a b. (a -> b) -> a -> b
$ Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL
amt :: Int
amt = Int
w forall a. Num a => a -> a -> a
- Int
cols
if Int
w forall a. Ord a => a -> a -> Bool
<= Int
cols
then forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
else forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
cropRightBy Int
amt forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
cropTopBy :: Int -> Widget n -> Widget n
cropTopBy :: forall n. Int -> Widget n -> Widget n
cropTopBy Int
rows Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let amt :: Int
amt = Image -> Int
V.imageHeight (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a. Num a => a -> a -> a
- Int
rows
cropped :: Image -> Image
cropped Image
img = if Int
amt forall a. Ord a => a -> a -> Bool
< Int
0 then Image
V.emptyImage else Int -> Image -> Image
V.cropTop Int
amt Image
img
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall n. Location -> Result n -> Result n
addResultOffset (DisplayRegion -> Location
Location (Int
0, -Int
1 forall a. Num a => a -> a -> a
* Int
rows))
forall a b. (a -> b) -> a -> b
$ Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Image -> Image
cropped
cropTopTo :: Int -> Widget n -> Widget n
cropTopTo :: forall n. Int -> Widget n -> Widget n
cropTopTo Int
rows Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let h :: Int
h = Image -> Int
V.imageHeight forall a b. (a -> b) -> a -> b
$ Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL
amt :: Int
amt = Int
h forall a. Num a => a -> a -> a
- Int
rows
if Int
h forall a. Ord a => a -> a -> Bool
<= Int
rows
then forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
else forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
cropTopBy Int
amt forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
cropBottomBy :: Int -> Widget n -> Widget n
cropBottomBy :: forall n. Int -> Widget n -> Widget n
cropBottomBy Int
rows Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let amt :: Int
amt = Image -> Int
V.imageHeight (Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a. Num a => a -> a -> a
- Int
rows
cropped :: Image -> Image
cropped Image
img = if Int
amt forall a. Ord a => a -> a -> Bool
< Int
0 then Image
V.emptyImage else Int -> Image -> Image
V.cropBottom Int
amt Image
img
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ Image -> Image
cropped
cropBottomTo :: Int -> Widget n -> Widget n
cropBottomTo :: forall n. Int -> Widget n -> Widget n
cropBottomTo Int
rows Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let h :: Int
h = Image -> Int
V.imageHeight forall a b. (a -> b) -> a -> b
$ Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL
amt :: Int
amt = Int
h forall a. Num a => a -> a -> a
- Int
rows
if Int
h forall a. Ord a => a -> a -> Bool
<= Int
rows
then forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
else forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
cropBottomBy Int
amt forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result
showCursor :: n -> Location -> Widget n -> Widget n
showCursor :: forall n. n -> Location -> Widget n -> Widget n
showCursor n
n Location
cloc Widget n
p = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
(forall n. Lens' (Result n) [CursorLocation n]
cursorsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall n. Location -> Maybe n -> Bool -> CursorLocation n
CursorLocation Location
cloc (forall a. a -> Maybe a
Just n
n) Bool
Trueforall a. a -> [a] -> [a]
:)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
putCursor :: n -> Location -> Widget n -> Widget n
putCursor :: forall n. n -> Location -> Widget n -> Widget n
putCursor n
n Location
cloc Widget n
p = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
(forall n. Lens' (Result n) [CursorLocation n]
cursorsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall n. Location -> Maybe n -> Bool -> CursorLocation n
CursorLocation Location
cloc (forall a. a -> Maybe a
Just n
n) Bool
Falseforall a. a -> [a] -> [a]
:)) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
hRelease :: Widget n -> Maybe (Widget n)
hRelease :: forall n. Widget n -> Maybe (Widget n)
hRelease Widget n
p =
case forall n. Widget n -> Size
hSize Widget n
p of
Size
Fixed -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Int
availWidthL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
unrestricted) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
Size
Greedy -> forall a. Maybe a
Nothing
vRelease :: Widget n -> Maybe (Widget n)
vRelease :: forall n. Widget n -> Maybe (Widget n)
vRelease Widget n
p =
case forall n. Widget n -> Size
vSize Widget n
p of
Size
Fixed -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) Size
Greedy forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Int
availHeightL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
unrestricted) (forall n. Widget n -> RenderM n (Result n)
render Widget n
p)
Size
Greedy -> forall a. Maybe a
Nothing
cached :: (Ord n) => n -> Widget n -> Widget n
cached :: forall n. Ord n => n -> Widget n -> Widget n
cached n
n Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$ do
Maybe ([n], Result n)
result <- forall n. Ord n => n -> RenderM n (Maybe ([n], Result n))
cacheLookup n
n
case Maybe ([n], Result n)
result of
Just ([n]
clickables, Result n
prevResult) -> do
forall n. Lens' (RenderState n) [n]
clickableNamesL forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= ([n]
clickables forall a. [a] -> [a] -> [a]
++)
forall (m :: * -> *) a. Monad m => a -> m a
return Result n
prevResult
Maybe ([n], Result n)
Nothing -> do
Result n
wResult <- forall n. Widget n -> RenderM n (Result n)
render Widget n
w
[n]
clickables <- forall n. Ord n => Result n -> RenderM n [n]
renderedClickables Result n
wResult
forall n. Ord n => n -> ([n], Result n) -> RenderM n ()
cacheUpdate n
n ([n]
clickables, Result n
wResult forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. Monoid a => a
mempty)
forall (m :: * -> *) a. Monad m => a -> m a
return Result n
wResult
where
renderedClickables :: (Ord n) => Result n -> RenderM n [n]
renderedClickables :: forall n. Ord n => Result n -> RenderM n [n]
renderedClickables Result n
renderResult = do
[n]
allClickables <- forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use forall n. Lens' (RenderState n) [n]
clickableNamesL
forall (m :: * -> *) a. Monad m => a -> m a
return [forall n. Extent n -> n
extentName Extent n
e | Extent n
e <- Result n
renderResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) [Extent n]
extentsL, forall n. Extent n -> n
extentName Extent n
e forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [n]
allClickables]
cacheLookup :: (Ord n) => n -> RenderM n (Maybe ([n], Result n))
cacheLookup :: forall n. Ord n => n -> RenderM n (Maybe ([n], Result n))
cacheLookup n
n = do
Map n ([n], Result n)
cache <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) (Map n ([n], Result n))
renderCacheL)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup n
n Map n ([n], Result n)
cache
cacheUpdate :: Ord n => n -> ([n], Result n) -> RenderM n ()
cacheUpdate :: forall n. Ord n => n -> ([n], Result n) -> RenderM n ()
cacheUpdate n
n ([n], Result n)
r = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall n. Lens' (RenderState n) (Map n ([n], Result n))
renderCacheL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert n
n ([n], Result n)
r)
withVScrollBars :: VScrollBarOrientation -> Widget n -> Widget n
withVScrollBars :: forall n. VScrollBarOrientation -> Widget n -> Widget n
withVScrollBars VScrollBarOrientation
orientation Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) (Maybe VScrollBarOrientation)
ctxVScrollBarOrientationL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just VScrollBarOrientation
orientation) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
withVScrollBarHandles :: Widget n -> Widget n
withVScrollBarHandles :: forall n. Widget n -> Widget n
withVScrollBarHandles Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Bool
ctxVScrollBarShowHandlesL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
withVScrollBarRenderer :: ScrollbarRenderer n -> Widget n -> Widget n
withVScrollBarRenderer :: forall n. ScrollbarRenderer n -> Widget n -> Widget n
withVScrollBarRenderer ScrollbarRenderer n
r Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) (Maybe (ScrollbarRenderer n))
ctxVScrollBarRendererL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just ScrollbarRenderer n
r) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
verticalScrollbarRenderer :: ScrollbarRenderer n
verticalScrollbarRenderer :: forall n. ScrollbarRenderer n
verticalScrollbarRenderer =
ScrollbarRenderer { renderScrollbar :: Widget n
renderScrollbar = forall n. Char -> Widget n
fill Char
'█'
, renderScrollbarTrough :: Widget n
renderScrollbarTrough = forall n. Char -> Widget n
fill Char
' '
, renderScrollbarHandleBefore :: Widget n
renderScrollbarHandleBefore = forall n. String -> Widget n
str String
"^"
, renderScrollbarHandleAfter :: Widget n
renderScrollbarHandleAfter = forall n. String -> Widget n
str String
"v"
}
withHScrollBars :: HScrollBarOrientation -> Widget n -> Widget n
withHScrollBars :: forall n. HScrollBarOrientation -> Widget n -> Widget n
withHScrollBars HScrollBarOrientation
orientation Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) (Maybe HScrollBarOrientation)
ctxHScrollBarOrientationL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just HScrollBarOrientation
orientation) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
withClickableHScrollBars :: (ClickableScrollbarElement -> n -> n) -> Widget n -> Widget n
withClickableHScrollBars :: forall n.
(ClickableScrollbarElement -> n -> n) -> Widget n -> Widget n
withClickableHScrollBars ClickableScrollbarElement -> n -> n
f Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n.
Lens' (Context n) (Maybe (ClickableScrollbarElement -> n -> n))
ctxHScrollBarClickableConstrL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just ClickableScrollbarElement -> n -> n
f) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
withClickableVScrollBars :: (ClickableScrollbarElement -> n -> n) -> Widget n -> Widget n
withClickableVScrollBars :: forall n.
(ClickableScrollbarElement -> n -> n) -> Widget n -> Widget n
withClickableVScrollBars ClickableScrollbarElement -> n -> n
f Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n.
Lens' (Context n) (Maybe (ClickableScrollbarElement -> n -> n))
ctxVScrollBarClickableConstrL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just ClickableScrollbarElement -> n -> n
f) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
withHScrollBarHandles :: Widget n -> Widget n
withHScrollBarHandles :: forall n. Widget n -> Widget n
withHScrollBarHandles Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) Bool
ctxHScrollBarShowHandlesL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Bool
True) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
withHScrollBarRenderer :: ScrollbarRenderer n -> Widget n -> Widget n
withHScrollBarRenderer :: forall n. ScrollbarRenderer n -> Widget n -> Widget n
withHScrollBarRenderer ScrollbarRenderer n
r Widget n
w =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
w) (forall n. Widget n -> Size
vSize Widget n
w) forall a b. (a -> b) -> a -> b
$
forall r' r (m :: * -> *) a.
(r' -> r) -> ReaderT r m a -> ReaderT r' m a
withReaderT (forall n. Lens' (Context n) (Maybe (ScrollbarRenderer n))
ctxHScrollBarRendererL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. a -> Maybe a
Just ScrollbarRenderer n
r) (forall n. Widget n -> RenderM n (Result n)
render Widget n
w)
horizontalScrollbarRenderer :: ScrollbarRenderer n
horizontalScrollbarRenderer :: forall n. ScrollbarRenderer n
horizontalScrollbarRenderer =
ScrollbarRenderer { renderScrollbar :: Widget n
renderScrollbar = forall n. Char -> Widget n
fill Char
'█'
, renderScrollbarTrough :: Widget n
renderScrollbarTrough = forall n. Char -> Widget n
fill Char
' '
, renderScrollbarHandleBefore :: Widget n
renderScrollbarHandleBefore = forall n. String -> Widget n
str String
"<"
, renderScrollbarHandleAfter :: Widget n
renderScrollbarHandleAfter = forall n. String -> Widget n
str String
">"
}
viewport :: (Ord n, Show n)
=> n
-> ViewportType
-> Widget n
-> Widget n
viewport :: forall n.
(Ord n, Show n) =>
n -> ViewportType -> Widget n -> Widget n
viewport n
vpname ViewportType
typ Widget n
p =
forall n. Ord n => n -> Widget n -> Widget n
clickable n
vpname forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Greedy forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let vsOrientation :: Maybe VScrollBarOrientation
vsOrientation = forall n. Context n -> Maybe VScrollBarOrientation
ctxVScrollBarOrientation Context n
c
hsOrientation :: Maybe HScrollBarOrientation
hsOrientation = forall n. Context n -> Maybe HScrollBarOrientation
ctxHScrollBarOrientation Context n
c
vsRenderer :: ScrollbarRenderer n
vsRenderer = forall a. a -> Maybe a -> a
fromMaybe forall n. ScrollbarRenderer n
verticalScrollbarRenderer (forall n. Context n -> Maybe (ScrollbarRenderer n)
ctxVScrollBarRenderer Context n
c)
hsRenderer :: ScrollbarRenderer n
hsRenderer = forall a. a -> Maybe a -> a
fromMaybe forall n. ScrollbarRenderer n
horizontalScrollbarRenderer (forall n. Context n -> Maybe (ScrollbarRenderer n)
ctxHScrollBarRenderer Context n
c)
showVHandles :: Bool
showVHandles = forall n. Context n -> Bool
ctxVScrollBarShowHandles Context n
c
showHHandles :: Bool
showHHandles = forall n. Context n -> Bool
ctxHScrollBarShowHandles Context n
c
vsbClickableConstr :: Maybe (ClickableScrollbarElement -> n -> n)
vsbClickableConstr = forall n. Context n -> Maybe (ClickableScrollbarElement -> n -> n)
ctxVScrollBarClickableConstr Context n
c
hsbClickableConstr :: Maybe (ClickableScrollbarElement -> n -> n)
hsbClickableConstr = forall n. Context n -> Maybe (ClickableScrollbarElement -> n -> n)
ctxHScrollBarClickableConstr Context n
c
let observeName :: (Ord n, Show n) => n -> RenderM n ()
observeName :: forall n. (Ord n, Show n) => n -> RenderM n ()
observeName n
n = do
Set n
observed <- forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use forall n. Lens' (RenderState n) (Set n)
observedNamesL
case forall a. Ord a => a -> Set a -> Bool
S.member n
n Set n
observed of
Bool
False -> forall n. Lens' (RenderState n) (Set n)
observedNamesL forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= forall a. Ord a => a -> Set a -> Set a
S.insert n
n
Bool
True ->
forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"Error: while rendering the interface, the name " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show n
n forall a. Semigroup a => a -> a -> a
<>
String
" was seen more than once. You should ensure that all of the widgets " forall a. Semigroup a => a -> a -> a
<>
String
"in each interface have unique name values. This means either " forall a. Semigroup a => a -> a -> a
<>
String
"using a different name type or adding constructors to your " forall a. Semigroup a => a -> a -> a
<>
String
"existing one and using those to name your widgets. For more " forall a. Semigroup a => a -> a -> a
<>
String
"information, see the \"Resource Names\" section of the Brick User Guide."
forall n. (Ord n, Show n) => n -> RenderM n ()
observeName n
vpname
let newVp :: Viewport
newVp = Int -> Int -> DisplayRegion -> DisplayRegion -> Viewport
VP Int
0 Int
0 DisplayRegion
newSize (Int
0, Int
0)
newSize :: DisplayRegion
newSize = (Int
newWidth, Int
newHeight)
newWidth :: Int
newWidth = Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL forall a. Num a => a -> a -> a
- Int
vSBWidth
newHeight :: Int
newHeight = Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL forall a. Num a => a -> a -> a
- Int
hSBHeight
vSBWidth :: Int
vSBWidth = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (forall a b. a -> b -> a
const Int
1) Maybe VScrollBarOrientation
vsOrientation
hSBHeight :: Int
hSBHeight = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Int
0 (forall a b. a -> b -> a
const Int
1) Maybe HScrollBarOrientation
hsOrientation
doInsert :: Maybe Viewport -> Maybe Viewport
doInsert (Just Viewport
vp) = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Viewport
vp forall a b. a -> (a -> b) -> b
& Lens' Viewport DisplayRegion
vpSize forall s t a b. ASetter s t a b -> b -> s -> t
.~ DisplayRegion
newSize
doInsert Maybe Viewport
Nothing = forall a. a -> Maybe a
Just Viewport
newVp
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall k a.
Ord k =>
(Maybe a -> Maybe a) -> k -> Map k a -> Map k a
M.alter Maybe Viewport -> Maybe Viewport
doInsert n
vpname))
let release :: Widget n -> Maybe (Widget n)
release = case ViewportType
typ of
ViewportType
Vertical -> forall n. Widget n -> Maybe (Widget n)
vRelease forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Int -> Widget n -> Widget n
hLimit Int
newWidth
ViewportType
Horizontal -> forall n. Widget n -> Maybe (Widget n)
hRelease forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall n. Int -> Widget n -> Widget n
vLimit Int
newHeight
ViewportType
Both -> forall n. Widget n -> Maybe (Widget n)
vRelease forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> forall n. Widget n -> Maybe (Widget n)
hRelease
released :: Widget n
released = case Widget n -> Maybe (Widget n)
release Widget n
p of
Just Widget n
w -> Widget n
w
Maybe (Widget n)
Nothing -> case ViewportType
typ of
ViewportType
Vertical -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"tried to embed an infinite-height " forall a. Semigroup a => a -> a -> a
<>
String
"widget in vertical viewport " forall a. Semigroup a => a -> a -> a
<> (forall a. Show a => a -> String
show n
vpname)
ViewportType
Horizontal -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"tried to embed an infinite-width " forall a. Semigroup a => a -> a -> a
<>
String
"widget in horizontal viewport " forall a. Semigroup a => a -> a -> a
<> (forall a. Show a => a -> String
show n
vpname)
ViewportType
Both -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"tried to embed an infinite-width or " forall a. Semigroup a => a -> a -> a
<>
String
"infinite-height widget in 'Both' type " forall a. Semigroup a => a -> a -> a
<>
String
"viewport " forall a. Semigroup a => a -> a -> a
<> (forall a. Show a => a -> String
show n
vpname)
Result n
initialResult <- forall n. Widget n -> RenderM n (Result n)
render Widget n
released
[(n, ScrollRequest)]
reqs <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) [(n, ScrollRequest)]
rsScrollRequestsL)
let relevantRequests :: [ScrollRequest]
relevantRequests = forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. (a -> Bool) -> [a] -> [a]
filter (\(n
n, ScrollRequest
_) -> n
n forall a. Eq a => a -> a -> Bool
== n
vpname) [(n, ScrollRequest)]
reqs
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Bool
null [ScrollRequest]
relevantRequests) forall a b. (a -> b) -> a -> b
$ do
Maybe Viewport
mVp <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to (forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup n
vpname))
case Maybe Viewport
mVp of
Maybe Viewport
Nothing -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"BUG: viewport: viewport name " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show n
vpname forall a. Semigroup a => a -> a -> a
<> String
" absent from viewport map"
Just Viewport
vp -> do
let updatedVp :: Viewport
updatedVp = [ScrollRequest] -> Viewport -> Viewport
applyRequests [ScrollRequest]
relevantRequests Viewport
vp
applyRequests :: [ScrollRequest] -> Viewport -> Viewport
applyRequests [] Viewport
v = Viewport
v
applyRequests (ScrollRequest
rq:[ScrollRequest]
rqs) Viewport
v =
case ViewportType
typ of
ViewportType
Horizontal -> ViewportType -> ScrollRequest -> Image -> Viewport -> Viewport
scrollTo ViewportType
typ ScrollRequest
rq (Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a b. (a -> b) -> a -> b
$ [ScrollRequest] -> Viewport -> Viewport
applyRequests [ScrollRequest]
rqs Viewport
v
ViewportType
Vertical -> ViewportType -> ScrollRequest -> Image -> Viewport -> Viewport
scrollTo ViewportType
typ ScrollRequest
rq (Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a b. (a -> b) -> a -> b
$ [ScrollRequest] -> Viewport -> Viewport
applyRequests [ScrollRequest]
rqs Viewport
v
ViewportType
Both -> ViewportType -> ScrollRequest -> Image -> Viewport -> Viewport
scrollTo ViewportType
Horizontal ScrollRequest
rq (Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a b. (a -> b) -> a -> b
$
ViewportType -> ScrollRequest -> Image -> Viewport -> Viewport
scrollTo ViewportType
Vertical ScrollRequest
rq (Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL) forall a b. (a -> b) -> a -> b
$
[ScrollRequest] -> Viewport -> Viewport
applyRequests [ScrollRequest]
rqs Viewport
v
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert n
vpname Viewport
updatedVp))
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a. Foldable t => t a -> Bool
null forall a b. (a -> b) -> a -> b
$ Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL) forall a b. (a -> b) -> a -> b
$ do
Maybe Viewport
mVp <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to (forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup n
vpname))
case Maybe Viewport
mVp of
Maybe Viewport
Nothing -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"BUG: viewport: viewport name " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show n
vpname forall a. Semigroup a => a -> a -> a
<> String
" absent from viewport map"
Just Viewport
vp -> do
let rqs :: [VisibilityRequest]
rqs = Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL
updateVp :: Viewport -> VisibilityRequest -> Viewport
updateVp Viewport
vp' VisibilityRequest
rq = case ViewportType
typ of
ViewportType
Both -> ViewportType -> VisibilityRequest -> Viewport -> Viewport
scrollToView ViewportType
Horizontal VisibilityRequest
rq forall a b. (a -> b) -> a -> b
$ ViewportType -> VisibilityRequest -> Viewport -> Viewport
scrollToView ViewportType
Vertical VisibilityRequest
rq Viewport
vp'
ViewportType
Horizontal -> ViewportType -> VisibilityRequest -> Viewport -> Viewport
scrollToView ViewportType
typ VisibilityRequest
rq Viewport
vp'
ViewportType
Vertical -> ViewportType -> VisibilityRequest -> Viewport -> Viewport
scrollToView ViewportType
typ VisibilityRequest
rq Viewport
vp'
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert n
vpname forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Viewport -> VisibilityRequest -> Viewport
updateVp Viewport
vp [VisibilityRequest]
rqs))
Maybe Viewport
mVp <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to (forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup n
vpname))
Viewport
vp <- case Maybe Viewport
mVp of
Maybe Viewport
Nothing -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"BUG: viewport: viewport name " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show n
vpname forall a. Semigroup a => a -> a -> a
<> String
" absent from viewport map"
Just Viewport
v -> forall (m :: * -> *) a. Monad m => a -> m a
return Viewport
v
let img :: Image
img = Result n
initialResultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageL
fixTop :: Viewport -> Viewport
fixTop Viewport
v = if Image -> Int
V.imageHeight Image
img forall a. Ord a => a -> a -> Bool
< Viewport
vforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
then Viewport
v forall a b. a -> (a -> b) -> b
& Lens' Viewport Int
vpTop forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
0
else Viewport
v
fixLeft :: Viewport -> Viewport
fixLeft Viewport
v = if Image -> Int
V.imageWidth Image
img forall a. Ord a => a -> a -> Bool
< Viewport
vforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
then Viewport
v forall a b. a -> (a -> b) -> b
& Lens' Viewport Int
vpLeft forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
0
else Viewport
v
updateContentSize :: Viewport -> Viewport
updateContentSize Viewport
v = Viewport
v forall a b. a -> (a -> b) -> b
& Lens' Viewport DisplayRegion
vpContentSize forall s t a b. ASetter s t a b -> b -> s -> t
.~ (Image -> Int
V.imageWidth Image
img, Image -> Int
V.imageHeight Image
img)
updateVp :: Viewport -> Viewport
updateVp = Viewport -> Viewport
updateContentSize forall b c a. (b -> c) -> (a -> b) -> a -> c
. case ViewportType
typ of
ViewportType
Both -> Viewport -> Viewport
fixLeft forall b c a. (b -> c) -> (a -> b) -> a -> c
. Viewport -> Viewport
fixTop
ViewportType
Horizontal -> Viewport -> Viewport
fixLeft
ViewportType
Vertical -> Viewport -> Viewport
fixTop
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify (forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert n
vpname (Viewport -> Viewport
updateVp Viewport
vp)))
Maybe Viewport
mVpFinal <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup n
vpname forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapL))
Viewport
vpFinal <- case Maybe Viewport
mVpFinal of
Maybe Viewport
Nothing -> forall a. HasCallStack => String -> a
error forall a b. (a -> b) -> a -> b
$ String
"BUG: viewport: viewport name " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show n
vpname forall a. Semigroup a => a -> a -> a
<> String
" absent from viewport map"
Just Viewport
v -> forall (m :: * -> *) a. Monad m => a -> m a
return Viewport
v
Result n
translated <- forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Location -> Widget n -> Widget n
translateBy (DisplayRegion -> Location
Location (-Int
1 forall a. Num a => a -> a -> a
* Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft, -Int
1 forall a. Num a => a -> a -> a
* Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop))
forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return Result n
initialResult
let addVScrollbar :: Widget n -> Widget n
addVScrollbar = case Maybe VScrollBarOrientation
vsOrientation of
Maybe VScrollBarOrientation
Nothing -> forall a. a -> a
id
Just VScrollBarOrientation
orientation ->
let sb :: Widget n
sb = forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Bool
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar ScrollbarRenderer n
vsRenderer n
vpname
Maybe (ClickableScrollbarElement -> n -> n)
vsbClickableConstr
Bool
showVHandles
(Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2)
(Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop)
(Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpContentSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2)
combine :: Widget n -> Widget n -> Widget n
combine = case VScrollBarOrientation
orientation of
VScrollBarOrientation
OnLeft -> forall n. Widget n -> Widget n -> Widget n
(<+>)
VScrollBarOrientation
OnRight -> forall a b c. (a -> b -> c) -> b -> a -> c
flip forall n. Widget n -> Widget n -> Widget n
(<+>)
in Widget n -> Widget n -> Widget n
combine Widget n
sb
addHScrollbar :: Widget n -> Widget n
addHScrollbar = case Maybe HScrollBarOrientation
hsOrientation of
Maybe HScrollBarOrientation
Nothing -> forall a. a -> a
id
Just HScrollBarOrientation
orientation ->
let sb :: Widget n
sb = forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Bool
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar ScrollbarRenderer n
hsRenderer n
vpname
Maybe (ClickableScrollbarElement -> n -> n)
hsbClickableConstr
Bool
showHHandles
(Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1)
(Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft)
(Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpContentSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1)
combine :: Widget n -> Widget n -> Widget n
combine = case HScrollBarOrientation
orientation of
HScrollBarOrientation
OnTop -> forall n. Widget n -> Widget n -> Widget n
(<=>)
HScrollBarOrientation
OnBottom -> forall a b c. (a -> b -> c) -> b -> a -> c
flip forall n. Widget n -> Widget n -> Widget n
(<=>)
in Widget n -> Widget n -> Widget n
combine Widget n
sb
let translatedSize :: DisplayRegion
translatedSize = ( Result n
translatedforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageWidth
, Result n
translatedforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageHeight
)
case DisplayRegion
translatedSize of
(Int
0, Int
0) -> do
let spaceFill :: Image
spaceFill = forall d. Integral d => Attr -> Char -> d -> d -> Image
V.charFill (Context n
cforall s a. s -> Getting a s a -> a
^.forall r n. Getting r (Context n) Attr
attrL) Char
' ' (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL) (Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Result n
translated forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) Image
imageL forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
spaceFill
forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. Monoid a => a
mempty
forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [Extent n]
extentsL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. Monoid a => a
mempty
DisplayRegion
_ -> forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ Widget n -> Widget n
addVScrollbar
forall a b. (a -> b) -> a -> b
$ Widget n -> Widget n
addHScrollbar
forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit (Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2)
forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit (Viewport
vpFinalforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1)
forall a b. (a -> b) -> a -> b
$ forall n. Padding -> Widget n -> Widget n
padBottom Padding
Max
forall a b. (a -> b) -> a -> b
$ forall n. Padding -> Widget n -> Widget n
padRight Padding
Max
forall a b. (a -> b) -> a -> b
$ forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Fixed
forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Result n
translated forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL forall s t a b. ASetter s t a b -> b -> s -> t
.~ forall a. Monoid a => a
mempty
scrollbarAttr :: AttrName
scrollbarAttr :: AttrName
scrollbarAttr = String -> AttrName
attrName String
"scrollbar"
scrollbarTroughAttr :: AttrName
scrollbarTroughAttr :: AttrName
scrollbarTroughAttr = AttrName
scrollbarAttr forall a. Semigroup a => a -> a -> a
<> String -> AttrName
attrName String
"trough"
scrollbarHandleAttr :: AttrName
scrollbarHandleAttr :: AttrName
scrollbarHandleAttr = AttrName
scrollbarAttr forall a. Semigroup a => a -> a -> a
<> String -> AttrName
attrName String
"handle"
maybeClick :: (Ord n)
=> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick :: forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
_ Maybe (ClickableScrollbarElement -> n -> n)
Nothing ClickableScrollbarElement
_ Widget n
w = Widget n
w
maybeClick n
n (Just ClickableScrollbarElement -> n -> n
f) ClickableScrollbarElement
el Widget n
w = forall n. Ord n => n -> Widget n -> Widget n
clickable (ClickableScrollbarElement -> n -> n
f ClickableScrollbarElement
el n
n) Widget n
w
verticalScrollbar :: (Ord n)
=> ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Bool
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar :: forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Bool
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar ScrollbarRenderer n
vsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Bool
False Int
vpHeight Int
vOffset Int
contentHeight =
forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar' ScrollbarRenderer n
vsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Int
vpHeight Int
vOffset Int
contentHeight
verticalScrollbar ScrollbarRenderer n
vsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Bool
True Int
vpHeight Int
vOffset Int
contentHeight =
forall n. [Widget n] -> Widget n
vBox [ forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBHandleBefore forall a b. (a -> b) -> a -> b
$
forall n. Int -> Widget n -> Widget n
hLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarHandleAttr forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbarHandleBefore ScrollbarRenderer n
vsRenderer
, forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar' ScrollbarRenderer n
vsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Int
vpHeight Int
vOffset Int
contentHeight
, forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBHandleAfter forall a b. (a -> b) -> a -> b
$
forall n. Int -> Widget n -> Widget n
hLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarHandleAttr forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbarHandleAfter ScrollbarRenderer n
vsRenderer
]
verticalScrollbar' :: (Ord n)
=> ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar' :: forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
verticalScrollbar' ScrollbarRenderer n
vsRenderer n
_ Maybe (ClickableScrollbarElement -> n -> n)
_ Int
vpHeight Int
_ Int
0 =
forall n. Int -> Widget n -> Widget n
hLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit Int
vpHeight forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
vsRenderer
verticalScrollbar' ScrollbarRenderer n
vsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Int
vpHeight Int
vOffset Int
contentHeight =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Fixed Size
Greedy forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let visibleContentPercent :: Double
visibleContentPercent :: Double
visibleContentPercent = forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
vpHeight forall a. Fractional a => a -> a -> a
/
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
contentHeight
ctxHeight :: Int
ctxHeight = Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availHeightL
sbSize :: Int
sbSize = forall a. Ord a => a -> a -> a
min Int
ctxHeight forall a b. (a -> b) -> a -> b
$
forall a. Ord a => a -> a -> a
max Int
1 forall a b. (a -> b) -> a -> b
$
forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ Double
visibleContentPercent forall a. Num a => a -> a -> a
* (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ctxHeight)
sbOffset :: Int
sbOffset = if Int
vOffset forall a. Eq a => a -> a -> Bool
== Int
0
then Int
0
else if Int
vOffset forall a. Eq a => a -> a -> Bool
== Int
contentHeight forall a. Num a => a -> a -> a
- Int
vpHeight
then Int
ctxHeight forall a. Num a => a -> a -> a
- Int
sbSize
else forall a. Ord a => a -> a -> a
min (Int
ctxHeight forall a. Num a => a -> a -> a
- Int
sbSize forall a. Num a => a -> a -> a
- Int
1) forall a b. (a -> b) -> a -> b
$
forall a. Ord a => a -> a -> a
max Int
1 forall a b. (a -> b) -> a -> b
$
forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ctxHeight forall a. Num a => a -> a -> a
*
(forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
vOffset forall a. Fractional a => a -> a -> a
/
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
contentHeight::Double)
sbAbove :: Widget n
sbAbove = forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBTroughBefore forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarTroughAttr forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit Int
sbOffset forall a b. (a -> b) -> a -> b
$
forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
vsRenderer
sbBelow :: Widget n
sbBelow = forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBTroughAfter forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarTroughAttr forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit (Int
ctxHeight forall a. Num a => a -> a -> a
- (Int
sbOffset forall a. Num a => a -> a -> a
+ Int
sbSize)) forall a b. (a -> b) -> a -> b
$
forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
vsRenderer
sbMiddle :: Widget n
sbMiddle = forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBBar forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarAttr forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit Int
sbSize forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbar ScrollbarRenderer n
vsRenderer
sb :: Widget n
sb = forall n. Int -> Widget n -> Widget n
hLimit Int
1 forall a b. (a -> b) -> a -> b
$
if Int
sbSize forall a. Eq a => a -> a -> Bool
== Int
ctxHeight
then forall n. Int -> Widget n -> Widget n
vLimit Int
sbSize forall a b. (a -> b) -> a -> b
$
forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
vsRenderer
else forall n. [Widget n] -> Widget n
vBox [Widget n
sbAbove, Widget n
sbMiddle, Widget n
sbBelow]
forall n. Widget n -> RenderM n (Result n)
render Widget n
sb
horizontalScrollbar :: (Ord n)
=> ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Bool
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar :: forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Bool
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar ScrollbarRenderer n
hsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Bool
False Int
vpWidth Int
hOffset Int
contentWidth =
forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar' ScrollbarRenderer n
hsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Int
vpWidth Int
hOffset Int
contentWidth
horizontalScrollbar ScrollbarRenderer n
hsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Bool
True Int
vpWidth Int
hOffset Int
contentWidth =
forall n. [Widget n] -> Widget n
hBox [ forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBHandleBefore forall a b. (a -> b) -> a -> b
$
forall n. Int -> Widget n -> Widget n
vLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarHandleAttr forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbarHandleBefore ScrollbarRenderer n
hsRenderer
, forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar' ScrollbarRenderer n
hsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Int
vpWidth Int
hOffset Int
contentWidth
, forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBHandleAfter forall a b. (a -> b) -> a -> b
$
forall n. Int -> Widget n -> Widget n
vLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarHandleAttr forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbarHandleAfter ScrollbarRenderer n
hsRenderer
]
horizontalScrollbar' :: (Ord n)
=> ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar' :: forall n.
Ord n =>
ScrollbarRenderer n
-> n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> Int
-> Int
-> Int
-> Widget n
horizontalScrollbar' ScrollbarRenderer n
hsRenderer n
_ Maybe (ClickableScrollbarElement -> n -> n)
_ Int
vpWidth Int
_ Int
0 =
forall n. Int -> Widget n -> Widget n
vLimit Int
1 forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit Int
vpWidth forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
hsRenderer
horizontalScrollbar' ScrollbarRenderer n
hsRenderer n
n Maybe (ClickableScrollbarElement -> n -> n)
constr Int
vpWidth Int
hOffset Int
contentWidth =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Fixed forall a b. (a -> b) -> a -> b
$ do
Context n
c <- forall n. RenderM n (Context n)
getContext
let visibleContentPercent :: Double
visibleContentPercent :: Double
visibleContentPercent = forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
vpWidth forall a. Fractional a => a -> a -> a
/
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
contentWidth
ctxWidth :: Int
ctxWidth = Context n
cforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Context n) Int
availWidthL
sbSize :: Int
sbSize = forall a. Ord a => a -> a -> a
min Int
ctxWidth forall a b. (a -> b) -> a -> b
$
forall a. Ord a => a -> a -> a
max Int
1 forall a b. (a -> b) -> a -> b
$
forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ Double
visibleContentPercent forall a. Num a => a -> a -> a
* (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ctxWidth)
sbOffset :: Int
sbOffset = if Int
hOffset forall a. Eq a => a -> a -> Bool
== Int
0
then Int
0
else if Int
hOffset forall a. Eq a => a -> a -> Bool
== Int
contentWidth forall a. Num a => a -> a -> a
- Int
vpWidth
then Int
ctxWidth forall a. Num a => a -> a -> a
- Int
sbSize
else forall a. Ord a => a -> a -> a
min (Int
ctxWidth forall a. Num a => a -> a -> a
- Int
sbSize forall a. Num a => a -> a -> a
- Int
1) forall a b. (a -> b) -> a -> b
$
forall a. Ord a => a -> a -> a
max Int
1 forall a b. (a -> b) -> a -> b
$
forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ctxWidth forall a. Num a => a -> a -> a
*
(forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
hOffset forall a. Fractional a => a -> a -> a
/
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
contentWidth::Double)
sbLeft :: Widget n
sbLeft = forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBTroughBefore forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarTroughAttr forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit Int
sbOffset forall a b. (a -> b) -> a -> b
$
forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
hsRenderer
sbRight :: Widget n
sbRight = forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBTroughAfter forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarTroughAttr forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit (Int
ctxWidth forall a. Num a => a -> a -> a
- (Int
sbOffset forall a. Num a => a -> a -> a
+ Int
sbSize)) forall a b. (a -> b) -> a -> b
$
forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
hsRenderer
sbMiddle :: Widget n
sbMiddle = forall n.
Ord n =>
n
-> Maybe (ClickableScrollbarElement -> n -> n)
-> ClickableScrollbarElement
-> Widget n
-> Widget n
maybeClick n
n Maybe (ClickableScrollbarElement -> n -> n)
constr ClickableScrollbarElement
SBBar forall a b. (a -> b) -> a -> b
$
forall n. AttrName -> Widget n -> Widget n
withDefAttr AttrName
scrollbarAttr forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit Int
sbSize forall a b. (a -> b) -> a -> b
$ forall n. ScrollbarRenderer n -> Widget n
renderScrollbar ScrollbarRenderer n
hsRenderer
sb :: Widget n
sb = forall n. Int -> Widget n -> Widget n
vLimit Int
1 forall a b. (a -> b) -> a -> b
$
if Int
sbSize forall a. Eq a => a -> a -> Bool
== Int
ctxWidth
then forall n. Int -> Widget n -> Widget n
hLimit Int
sbSize forall a b. (a -> b) -> a -> b
$
forall n. ScrollbarRenderer n -> Widget n
renderScrollbarTrough ScrollbarRenderer n
hsRenderer
else forall n. [Widget n] -> Widget n
hBox [Widget n
sbLeft, Widget n
sbMiddle, Widget n
sbRight]
forall n. Widget n -> RenderM n (Result n)
render Widget n
sb
unsafeLookupViewport :: (Ord n) => n -> RenderM n (Maybe Viewport)
unsafeLookupViewport :: forall n. Ord n => n -> RenderM n (Maybe Viewport)
unsafeLookupViewport n
name = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup n
name forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall s a. s -> Getting a s a -> a
^.forall n. Lens' (RenderState n) (Map n Viewport)
viewportMapL))
scrollTo :: ViewportType -> ScrollRequest -> V.Image -> Viewport -> Viewport
scrollTo :: ViewportType -> ScrollRequest -> Image -> Viewport -> Viewport
scrollTo ViewportType
Both ScrollRequest
_ Image
_ Viewport
_ = forall a. HasCallStack => String -> a
error String
"BUG: called scrollTo on viewport type 'Both'"
scrollTo ViewportType
Vertical ScrollRequest
req Image
img Viewport
vp = Viewport
vp forall a b. a -> (a -> b) -> b
& Lens' Viewport Int
vpTop forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
newVStart
where
newVStart :: Int
newVStart = forall a. Ord a => a -> a -> a -> a
clamp Int
0 (Image -> Int
V.imageHeight Image
img forall a. Num a => a -> a -> a
- Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2) Int
adjustedAmt
adjustedAmt :: Int
adjustedAmt = case ScrollRequest
req of
VScrollBy Int
amt -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop forall a. Num a => a -> a -> a
+ Int
amt
VScrollPage Direction
Up -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop forall a. Num a => a -> a -> a
- Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
VScrollPage Direction
Down -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop forall a. Num a => a -> a -> a
+ Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
ScrollRequest
VScrollToBeginning -> Int
0
ScrollRequest
VScrollToEnd -> Image -> Int
V.imageHeight Image
img forall a. Num a => a -> a -> a
- Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
SetTop Int
i -> Int
i
ScrollRequest
_ -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop
scrollTo ViewportType
Horizontal ScrollRequest
req Image
img Viewport
vp = Viewport
vp forall a b. a -> (a -> b) -> b
& Lens' Viewport Int
vpLeft forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
newHStart
where
newHStart :: Int
newHStart = forall a. Ord a => a -> a -> a -> a
clamp Int
0 (Image -> Int
V.imageWidth Image
img forall a. Num a => a -> a -> a
- Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1) Int
adjustedAmt
adjustedAmt :: Int
adjustedAmt = case ScrollRequest
req of
HScrollBy Int
amt -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft forall a. Num a => a -> a -> a
+ Int
amt
HScrollPage Direction
Up -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft forall a. Num a => a -> a -> a
- Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
HScrollPage Direction
Down -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft forall a. Num a => a -> a -> a
+ Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
ScrollRequest
HScrollToBeginning -> Int
0
ScrollRequest
HScrollToEnd -> Image -> Int
V.imageWidth Image
img forall a. Num a => a -> a -> a
- Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
SetLeft Int
i -> Int
i
ScrollRequest
_ -> Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft
scrollToView :: ViewportType -> VisibilityRequest -> Viewport -> Viewport
scrollToView :: ViewportType -> VisibilityRequest -> Viewport -> Viewport
scrollToView ViewportType
Both VisibilityRequest
_ Viewport
_ = forall a. HasCallStack => String -> a
error String
"BUG: called scrollToView on 'Both' type viewport"
scrollToView ViewportType
Vertical VisibilityRequest
rq Viewport
vp = Viewport
vp forall a b. a -> (a -> b) -> b
& Lens' Viewport Int
vpTop forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
newVStart
where
curStart :: Int
curStart = Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpTop
curEnd :: Int
curEnd = Int
curStart forall a. Num a => a -> a -> a
+ Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
reqStart :: Int
reqStart = VisibilityRequest
rqforall s a. s -> Getting a s a -> a
^.Lens' VisibilityRequest Location
vrPositionLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. TerminalLocation a => Lens' a Int
locationRowL
reqEnd :: Int
reqEnd = VisibilityRequest
rqforall s a. s -> Getting a s a -> a
^.Lens' VisibilityRequest Location
vrPositionLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. TerminalLocation a => Lens' a Int
locationRowL forall a. Num a => a -> a -> a
+ VisibilityRequest
rqforall s a. s -> Getting a s a -> a
^.Lens' VisibilityRequest DisplayRegion
vrSizeLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field2 s t a b => Lens s t a b
_2
newVStart :: Int
newVStart :: Int
newVStart = if Int
reqStart forall a. Ord a => a -> a -> Bool
< Int
vStartEndVisible
then Int
reqStart
else Int
vStartEndVisible
vStartEndVisible :: Int
vStartEndVisible = if Int
reqEnd forall a. Ord a => a -> a -> Bool
< Int
curEnd
then Int
curStart
else Int
curStart forall a. Num a => a -> a -> a
+ (Int
reqEnd forall a. Num a => a -> a -> a
- Int
curEnd)
scrollToView ViewportType
Horizontal VisibilityRequest
rq Viewport
vp = Viewport
vp forall a b. a -> (a -> b) -> b
& Lens' Viewport Int
vpLeft forall s t a b. ASetter s t a b -> b -> s -> t
.~ Int
newHStart
where
curStart :: Int
curStart = Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport Int
vpLeft
curEnd :: Int
curEnd = Int
curStart forall a. Num a => a -> a -> a
+ Viewport
vpforall s a. s -> Getting a s a -> a
^.Lens' Viewport DisplayRegion
vpSizeforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
reqStart :: Int
reqStart = VisibilityRequest
rqforall s a. s -> Getting a s a -> a
^.Lens' VisibilityRequest Location
vrPositionLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. TerminalLocation a => Lens' a Int
locationColumnL
reqEnd :: Int
reqEnd = VisibilityRequest
rqforall s a. s -> Getting a s a -> a
^.Lens' VisibilityRequest Location
vrPositionLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall a. TerminalLocation a => Lens' a Int
locationColumnL forall a. Num a => a -> a -> a
+ VisibilityRequest
rqforall s a. s -> Getting a s a -> a
^.Lens' VisibilityRequest DisplayRegion
vrSizeLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s t a b. Field1 s t a b => Lens s t a b
_1
newHStart :: Int
newHStart :: Int
newHStart = if Int
reqStart forall a. Ord a => a -> a -> Bool
< Int
hStartEndVisible
then Int
reqStart
else Int
hStartEndVisible
hStartEndVisible :: Int
hStartEndVisible = if Int
reqEnd forall a. Ord a => a -> a -> Bool
< Int
curEnd
then Int
curStart
else Int
curStart forall a. Num a => a -> a -> a
+ (Int
reqEnd forall a. Num a => a -> a -> a
- Int
curEnd)
visible :: Widget n -> Widget n
visible :: forall n. Widget n -> Widget n
visible Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
let imageSize :: DisplayRegion
imageSize = ( Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageWidth
, Result n
resultforall s a. s -> Getting a s a -> a
^.forall n. Lens' (Result n) Image
imageLforall b c a. (b -> c) -> (a -> b) -> a -> c
.forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
V.imageHeight
)
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if DisplayRegion
imageSizeforall s a. s -> Getting a s a -> a
^.forall s t a b. Field1 s t a b => Lens s t a b
_1 forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& DisplayRegion
imageSizeforall s a. s -> Getting a s a -> a
^.forall s t a b. Field2 s t a b => Lens s t a b
_2 forall a. Ord a => a -> a -> Bool
> Int
0
then Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Location -> DisplayRegion -> VisibilityRequest
VR (DisplayRegion -> Location
Location (Int
0, Int
0)) DisplayRegion
imageSize forall a. a -> [a] -> [a]
:)
else Result n
result
visibleRegion :: Location -> V.DisplayRegion -> Widget n -> Widget n
visibleRegion :: forall n. Location -> DisplayRegion -> Widget n -> Widget n
visibleRegion Location
vrloc DisplayRegion
sz Widget n
p =
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
p) (forall n. Widget n -> Size
vSize Widget n
p) forall a b. (a -> b) -> a -> b
$ do
Result n
result <- forall n. Widget n -> RenderM n (Result n)
render Widget n
p
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if DisplayRegion
szforall s a. s -> Getting a s a -> a
^.forall s t a b. Field1 s t a b => Lens s t a b
_1 forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& DisplayRegion
szforall s a. s -> Getting a s a -> a
^.forall s t a b. Field2 s t a b => Lens s t a b
_2 forall a. Ord a => a -> a -> Bool
> Int
0
then Result n
result forall a b. a -> (a -> b) -> b
& forall n. Lens' (Result n) [VisibilityRequest]
visibilityRequestsL forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Location -> DisplayRegion -> VisibilityRequest
VR Location
vrloc DisplayRegion
sz forall a. a -> [a] -> [a]
:)
else Result n
result
{-# NOINLINE (<+>) #-}
(<+>) :: Widget n
-> Widget n
-> Widget n
<+> :: forall n. Widget n -> Widget n -> Widget n
(<+>) Widget n
a Widget n
b = forall n. [Widget n] -> Widget n
hBox [Widget n
a, Widget n
b]
{-# NOINLINE (<=>) #-}
(<=>) :: Widget n
-> Widget n
-> Widget n
<=> :: forall n. Widget n -> Widget n -> Widget n
(<=>) Widget n
a Widget n
b = forall n. [Widget n] -> Widget n
vBox [Widget n
a, Widget n
b]
{-# RULES
"baseHbox" forall a b . a <+> b = hBox [a, b]
"hBox2" forall as bs . hBox [hBox as, hBox bs] = hBox (as ++ bs)
"hboxL" forall as b . hBox [hBox as, b] = hBox (as ++ [b])
"hboxR" forall a bs . hBox [a, hBox bs] = hBox (a : bs)
"baseVbox" forall a b . a <=> b = vBox [a, b]
"vBox2" forall as bs . vBox [vBox as, vBox bs] = vBox (as ++ bs)
"vboxL" forall as b . vBox [vBox as, b] = vBox (as ++ [b])
"vboxR" forall a bs . vBox [a, vBox bs] = vBox (a : bs)
#-}