-- | Extensions to "Brick.Widgets.Border"
module Brick.Widgets.Border.Utils (borderLeft) where

import Brick
import Brick.Widgets.Border
import Graphics.Vty

import Lens.Micro

-- | Draw a vertical border on the left side of a widget.
borderLeft :: Widget n -> Widget n
borderLeft :: forall n. Widget n -> Widget n
borderLeft Widget n
wrapped = forall n. Size -> Size -> RenderM n (Result n) -> Widget n
Widget (forall n. Widget n -> Size
hSize Widget n
wrapped) (forall n. Widget n -> Size
vSize Widget n
wrapped) forall a b. (a -> b) -> a -> b
$ do
  Context n
c <- forall n. RenderM n (Context n)
getContext

  Result n
wrappedRes <- forall n. Widget n -> RenderM n (Result n)
render forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
hLimit (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
1)
                       forall a b. (a -> b) -> a -> b
$ Widget n
wrapped

  let withBorder :: Widget n
withBorder = forall n. Widget n
vBorder 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
wrappedRes)
      width :: Int
width = Result n
wrappedResforall 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
imageWidth forall a. Num a => a -> a -> a
+ Int
1
      height :: Int
height = Result n
wrappedResforall 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
imageHeight

  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
width forall a b. (a -> b) -> a -> b
$ forall n. Int -> Widget n -> Widget n
vLimit Int
height forall a b. (a -> b) -> a -> b
$ Widget n
withBorder