module Brick.Widgets.Center
(
hCenter
, hCenterWith
, hCenterLayer
, vCenter
, vCenterWith
, vCenterLayer
, center
, centerWith
, centerLayer
, centerAbout
)
where
import Lens.Micro ((^.), (&), (.~), to)
import Data.Maybe (fromMaybe)
import Graphics.Vty (imageWidth, imageHeight, horizCat, charFill, vertCat,
translateX, translateY)
import Brick.Types
import Brick.Widgets.Core
hCenter :: Widget n -> Widget n
hCenter :: forall n. Widget n -> Widget n
hCenter = Maybe Char -> Widget n -> Widget n
forall n. Maybe Char -> Widget n -> Widget n
hCenterWith Maybe Char
forall a. Maybe a
Nothing
hCenterLayer :: Widget n -> Widget n
hCenterLayer :: forall n. Widget n -> Widget n
hCenterLayer Widget n
p =
Size -> Size -> RenderM n (Result n) -> Widget n
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy (Widget n -> Size
forall n. Widget n -> Size
vSize Widget n
p) (RenderM n (Result n) -> Widget n)
-> RenderM n (Result n) -> Widget n
forall a b. (a -> b) -> a -> b
$ do
Result n
result <- Widget n -> RenderM n (Result n)
forall n. Widget n -> RenderM n (Result n)
render Widget n
p
Context n
c <- RenderM n (Context n)
forall n. RenderM n (Context n)
getContext
let rWidth :: Int
rWidth = Result n
resultResult n -> Getting Int (Result n) Int -> Int
forall s a. s -> Getting a s a -> a
^.(Image -> Const Int Image) -> Result n -> Const Int (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL((Image -> Const Int Image) -> Result n -> Const Int (Result n))
-> ((Int -> Const Int Int) -> Image -> Const Int Image)
-> Getting Int (Result n) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Image -> Int) -> SimpleGetter Image Int
forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
imageWidth
leftPaddingAmount :: Int
leftPaddingAmount = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availWidthL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
rWidth) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
paddedImage :: Image
paddedImage = Int -> Image -> Image
translateX Int
leftPaddingAmount (Image -> Image) -> Image -> Image
forall a b. (a -> b) -> a -> b
$ Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL
off :: Location
off = (Int, Int) -> Location
Location (Int
leftPaddingAmount, Int
0)
if Int
leftPaddingAmount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result else
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result n -> RenderM n (Result n))
-> Result n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ Location -> Result n -> Result n
forall n. Location -> Result n -> Result n
addResultOffset Location
off
(Result n -> Result n) -> Result n -> Result n
forall a b. (a -> b) -> a -> b
$ Result n
result Result n -> (Result n -> Result n) -> Result n
forall a b. a -> (a -> b) -> b
& (Image -> Identity Image) -> Result n -> Identity (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL ((Image -> Identity Image) -> Result n -> Identity (Result n))
-> Image -> Result n -> Result n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
paddedImage
hCenterWith :: Maybe Char -> Widget n -> Widget n
hCenterWith :: forall n. Maybe Char -> Widget n -> Widget n
hCenterWith Maybe Char
mChar Widget n
p =
let ch :: Char
ch = Char -> Maybe Char -> Char
forall a. a -> Maybe a -> a
fromMaybe Char
' ' Maybe Char
mChar
in Size -> Size -> RenderM n (Result n) -> Widget n
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy (Widget n -> Size
forall n. Widget n -> Size
vSize Widget n
p) (RenderM n (Result n) -> Widget n)
-> RenderM n (Result n) -> Widget n
forall a b. (a -> b) -> a -> b
$ do
Result n
result <- Widget n -> RenderM n (Result n)
forall n. Widget n -> RenderM n (Result n)
render Widget n
p
Context n
c <- RenderM n (Context n)
forall n. RenderM n (Context n)
getContext
let rWidth :: Int
rWidth = Result n
resultResult n -> Getting Int (Result n) Int -> Int
forall s a. s -> Getting a s a -> a
^.(Image -> Const Int Image) -> Result n -> Const Int (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL((Image -> Const Int Image) -> Result n -> Const Int (Result n))
-> ((Int -> Const Int Int) -> Image -> Const Int Image)
-> Getting Int (Result n) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Image -> Int) -> SimpleGetter Image Int
forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
imageWidth
rHeight :: Int
rHeight = Result n
resultResult n -> Getting Int (Result n) Int -> Int
forall s a. s -> Getting a s a -> a
^.(Image -> Const Int Image) -> Result n -> Const Int (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL((Image -> Const Int Image) -> Result n -> Const Int (Result n))
-> ((Int -> Const Int Int) -> Image -> Const Int Image)
-> Getting Int (Result n) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Image -> Int) -> SimpleGetter Image Int
forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
imageHeight
remainder :: Int
remainder = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availWidthL Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
leftPaddingAmount Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2)
leftPaddingAmount :: Int
leftPaddingAmount = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availWidthL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
rWidth) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
rightPaddingAmount :: Int
rightPaddingAmount = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
leftPaddingAmount Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
remainder
leftPadding :: Image
leftPadding = Attr -> Char -> Int -> Int -> Image
forall d. Integral d => Attr -> Char -> d -> d -> Image
charFill (Context n
cContext n -> Getting Attr (Context n) Attr -> Attr
forall s a. s -> Getting a s a -> a
^.Getting Attr (Context n) Attr
forall r n. Getting r (Context n) Attr
attrL) Char
ch Int
leftPaddingAmount Int
rHeight
rightPadding :: Image
rightPadding = Attr -> Char -> Int -> Int -> Image
forall d. Integral d => Attr -> Char -> d -> d -> Image
charFill (Context n
cContext n -> Getting Attr (Context n) Attr -> Attr
forall s a. s -> Getting a s a -> a
^.Getting Attr (Context n) Attr
forall r n. Getting r (Context n) Attr
attrL) Char
ch Int
rightPaddingAmount Int
rHeight
paddedImage :: Image
paddedImage = [Image] -> Image
horizCat [ Image
leftPadding
, Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL
, Image
rightPadding
]
off :: Location
off = (Int, Int) -> Location
Location (Int
leftPaddingAmount, Int
0)
if Int
leftPaddingAmount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& Int
rightPaddingAmount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result else
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result n -> RenderM n (Result n))
-> Result n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ Location -> Result n -> Result n
forall n. Location -> Result n -> Result n
addResultOffset Location
off
(Result n -> Result n) -> Result n -> Result n
forall a b. (a -> b) -> a -> b
$ Result n
result Result n -> (Result n -> Result n) -> Result n
forall a b. a -> (a -> b) -> b
& (Image -> Identity Image) -> Result n -> Identity (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL ((Image -> Identity Image) -> Result n -> Identity (Result n))
-> Image -> Result n -> Result n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
paddedImage
vCenter :: Widget n -> Widget n
vCenter :: forall n. Widget n -> Widget n
vCenter = Maybe Char -> Widget n -> Widget n
forall n. Maybe Char -> Widget n -> Widget n
vCenterWith Maybe Char
forall a. Maybe a
Nothing
vCenterLayer :: Widget n -> Widget n
vCenterLayer :: forall n. Widget n -> Widget n
vCenterLayer Widget n
p =
Size -> Size -> RenderM n (Result n) -> Widget n
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (Widget n -> Size
forall n. Widget n -> Size
hSize Widget n
p) Size
Greedy (RenderM n (Result n) -> Widget n)
-> RenderM n (Result n) -> Widget n
forall a b. (a -> b) -> a -> b
$ do
Result n
result <- Widget n -> RenderM n (Result n)
forall n. Widget n -> RenderM n (Result n)
render Widget n
p
Context n
c <- RenderM n (Context n)
forall n. RenderM n (Context n)
getContext
let rHeight :: Int
rHeight = Result n
resultResult n -> Getting Int (Result n) Int -> Int
forall s a. s -> Getting a s a -> a
^.(Image -> Const Int Image) -> Result n -> Const Int (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL((Image -> Const Int Image) -> Result n -> Const Int (Result n))
-> ((Int -> Const Int Int) -> Image -> Const Int Image)
-> Getting Int (Result n) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Image -> Int) -> SimpleGetter Image Int
forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
imageHeight
topPaddingAmount :: Int
topPaddingAmount = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
rHeight) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
paddedImage :: Image
paddedImage = Int -> Image -> Image
translateY Int
topPaddingAmount (Image -> Image) -> Image -> Image
forall a b. (a -> b) -> a -> b
$ Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL
off :: Location
off = (Int, Int) -> Location
Location (Int
0, Int
topPaddingAmount)
if Int
topPaddingAmount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result else
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result n -> RenderM n (Result n))
-> Result n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ Location -> Result n -> Result n
forall n. Location -> Result n -> Result n
addResultOffset Location
off
(Result n -> Result n) -> Result n -> Result n
forall a b. (a -> b) -> a -> b
$ Result n
result Result n -> (Result n -> Result n) -> Result n
forall a b. a -> (a -> b) -> b
& (Image -> Identity Image) -> Result n -> Identity (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL ((Image -> Identity Image) -> Result n -> Identity (Result n))
-> Image -> Result n -> Result n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
paddedImage
vCenterWith :: Maybe Char -> Widget n -> Widget n
vCenterWith :: forall n. Maybe Char -> Widget n -> Widget n
vCenterWith Maybe Char
mChar Widget n
p =
let ch :: Char
ch = Char -> Maybe Char -> Char
forall a. a -> Maybe a -> a
fromMaybe Char
' ' Maybe Char
mChar
in Size -> Size -> RenderM n (Result n) -> Widget n
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (Widget n -> Size
forall n. Widget n -> Size
hSize Widget n
p) Size
Greedy (RenderM n (Result n) -> Widget n)
-> RenderM n (Result n) -> Widget n
forall a b. (a -> b) -> a -> b
$ do
Result n
result <- Widget n -> RenderM n (Result n)
forall n. Widget n -> RenderM n (Result n)
render Widget n
p
Context n
c <- RenderM n (Context n)
forall n. RenderM n (Context n)
getContext
let rWidth :: Int
rWidth = Result n
resultResult n -> Getting Int (Result n) Int -> Int
forall s a. s -> Getting a s a -> a
^.(Image -> Const Int Image) -> Result n -> Const Int (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL((Image -> Const Int Image) -> Result n -> Const Int (Result n))
-> ((Int -> Const Int Int) -> Image -> Const Int Image)
-> Getting Int (Result n) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Image -> Int) -> SimpleGetter Image Int
forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
imageWidth
rHeight :: Int
rHeight = Result n
resultResult n -> Getting Int (Result n) Int -> Int
forall s a. s -> Getting a s a -> a
^.(Image -> Const Int Image) -> Result n -> Const Int (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL((Image -> Const Int Image) -> Result n -> Const Int (Result n))
-> ((Int -> Const Int Int) -> Image -> Const Int Image)
-> Getting Int (Result n) Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Image -> Int) -> SimpleGetter Image Int
forall s a. (s -> a) -> SimpleGetter s a
to Image -> Int
imageHeight
remainder :: Int
remainder = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL Int -> Int -> Int
forall a. Num a => a -> a -> a
- (Int
topPaddingAmount Int -> Int -> Int
forall a. Num a => a -> a -> a
* Int
2)
topPaddingAmount :: Int
topPaddingAmount = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ (Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
rHeight) Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
bottomPaddingAmount :: Int
bottomPaddingAmount = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Int
topPaddingAmount Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
remainder
topPadding :: Image
topPadding = Attr -> Char -> Int -> Int -> Image
forall d. Integral d => Attr -> Char -> d -> d -> Image
charFill (Context n
cContext n -> Getting Attr (Context n) Attr -> Attr
forall s a. s -> Getting a s a -> a
^.Getting Attr (Context n) Attr
forall r n. Getting r (Context n) Attr
attrL) Char
ch Int
rWidth Int
topPaddingAmount
bottomPadding :: Image
bottomPadding = Attr -> Char -> Int -> Int -> Image
forall d. Integral d => Attr -> Char -> d -> d -> Image
charFill (Context n
cContext n -> Getting Attr (Context n) Attr -> Attr
forall s a. s -> Getting a s a -> a
^.Getting Attr (Context n) Attr
forall r n. Getting r (Context n) Attr
attrL) Char
ch Int
rWidth Int
bottomPaddingAmount
paddedImage :: Image
paddedImage = [Image] -> Image
vertCat [ Image
topPadding
, Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL
, Image
bottomPadding
]
off :: Location
off = (Int, Int) -> Location
Location (Int
0, Int
topPaddingAmount)
if Int
topPaddingAmount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& Int
bottomPaddingAmount Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
0 then
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return Result n
result else
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result n -> RenderM n (Result n))
-> Result n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ Location -> Result n -> Result n
forall n. Location -> Result n -> Result n
addResultOffset Location
off
(Result n -> Result n) -> Result n -> Result n
forall a b. (a -> b) -> a -> b
$ Result n
result Result n -> (Result n -> Result n) -> Result n
forall a b. a -> (a -> b) -> b
& (Image -> Identity Image) -> Result n -> Identity (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL ((Image -> Identity Image) -> Result n -> Identity (Result n))
-> Image -> Result n -> Result n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
paddedImage
center :: Widget n -> Widget n
center :: forall n. Widget n -> Widget n
center = Maybe Char -> Widget n -> Widget n
forall n. Maybe Char -> Widget n -> Widget n
centerWith Maybe Char
forall a. Maybe a
Nothing
centerWith :: Maybe Char -> Widget n -> Widget n
centerWith :: forall n. Maybe Char -> Widget n -> Widget n
centerWith Maybe Char
c = Maybe Char -> Widget n -> Widget n
forall n. Maybe Char -> Widget n -> Widget n
vCenterWith Maybe Char
c (Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe Char -> Widget n -> Widget n
forall n. Maybe Char -> Widget n -> Widget n
hCenterWith Maybe Char
c
centerLayer :: Widget n -> Widget n
centerLayer :: forall n. Widget n -> Widget n
centerLayer = Widget n -> Widget n
forall n. Widget n -> Widget n
vCenterLayer (Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Widget n -> Widget n
forall n. Widget n -> Widget n
hCenterLayer
centerAbout :: Location -> Widget n -> Widget n
centerAbout :: forall n. Location -> Widget n -> Widget n
centerAbout Location
l Widget n
p =
Size -> Size -> RenderM n (Result n) -> Widget n
forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget Size
Greedy Size
Greedy (RenderM n (Result n) -> Widget n)
-> RenderM n (Result n) -> Widget n
forall a b. (a -> b) -> a -> b
$ do
Context n
c <- RenderM n (Context n)
forall n. RenderM n (Context n)
getContext
let centerW :: Int
centerW = Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availWidthL Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
centerH :: Int
centerH = Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL Int -> Int -> Int
forall a. Integral a => a -> a -> a
`div` Int
2
off :: Location
off = (Int, Int) -> Location
Location ( Int
centerW Int -> Int -> Int
forall a. Num a => a -> a -> a
- Location
lLocation -> Getting Int Location Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int Location Int
forall a. TerminalLocation a => Lens' a Int
Lens' Location Int
locationColumnL
, Int
centerH Int -> Int -> Int
forall a. Num a => a -> a -> a
- Location
lLocation -> Getting Int Location Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int Location Int
forall a. TerminalLocation a => Lens' a Int
Lens' Location Int
locationRowL
)
Result n
result <- Widget n -> RenderM n (Result n)
forall n. Widget n -> RenderM n (Result n)
render (Widget n -> RenderM n (Result n))
-> Widget n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ Location -> Widget n -> Widget n
forall n. Location -> Widget n -> Widget n
translateBy Location
off Widget n
p
let rightPaddingAmt :: Int
rightPaddingAmt = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availWidthL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Image -> Int
imageWidth (Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL)
bottomPaddingAmt :: Int
bottomPaddingAmt = Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int -> Int) -> Int -> Int
forall a b. (a -> b) -> a -> b
$ Context n
cContext n -> Getting Int (Context n) Int -> Int
forall s a. s -> Getting a s a -> a
^.Getting Int (Context n) Int
forall n (f :: * -> *).
Functor f =>
(Int -> f Int) -> Context n -> f (Context n)
availHeightL Int -> Int -> Int
forall a. Num a => a -> a -> a
- Image -> Int
imageHeight (Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL)
rightPadding :: Image
rightPadding = Attr -> Char -> Int -> Int -> Image
forall d. Integral d => Attr -> Char -> d -> d -> Image
charFill (Context n
cContext n -> Getting Attr (Context n) Attr -> Attr
forall s a. s -> Getting a s a -> a
^.Getting Attr (Context n) Attr
forall r n. Getting r (Context n) Attr
attrL) Char
' ' Int
rightPaddingAmt (Image -> Int
imageHeight (Image -> Int) -> Image -> Int
forall a b. (a -> b) -> a -> b
$ Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL)
bottomPadding :: Image
bottomPadding = Attr -> Char -> Int -> Int -> Image
forall d. Integral d => Attr -> Char -> d -> d -> Image
charFill (Context n
cContext n -> Getting Attr (Context n) Attr -> Attr
forall s a. s -> Getting a s a -> a
^.Getting Attr (Context n) Attr
forall r n. Getting r (Context n) Attr
attrL) Char
' ' (Image -> Int
imageWidth (Image -> Int) -> Image -> Int
forall a b. (a -> b) -> a -> b
$ Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL) Int
bottomPaddingAmt
paddedImg :: Image
paddedImg = [Image] -> Image
horizCat [[Image] -> Image
vertCat [Result n
resultResult n -> Getting Image (Result n) Image -> Image
forall s a. s -> Getting a s a -> a
^.Getting Image (Result n) Image
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL, Image
bottomPadding], Image
rightPadding]
Result n -> RenderM n (Result n)
forall a. a -> ReaderT (Context n) (State (RenderState n)) a
forall (m :: * -> *) a. Monad m => a -> m a
return (Result n -> RenderM n (Result n))
-> Result n -> RenderM n (Result n)
forall a b. (a -> b) -> a -> b
$ Result n
result Result n -> (Result n -> Result n) -> Result n
forall a b. a -> (a -> b) -> b
& (Image -> Identity Image) -> Result n -> Identity (Result n)
forall n (f :: * -> *).
Functor f =>
(Image -> f Image) -> Result n -> f (Result n)
imageL ((Image -> Identity Image) -> Result n -> Identity (Result n))
-> Image -> Result n -> Result n
forall s t a b. ASetter s t a b -> b -> s -> t
.~ Image
paddedImg