module Summoner.Tui.GroupBorder
( groupBorder
, (|>)
) where
import Brick (Edges (..), Padding (Max), Widget, padRight, vLimit, (<+>), (<=>))
import Brick.Forms (FormFieldState, (@@=))
import Brick.Widgets.Border (hBorder, hBorderWithLabel, joinableBorder, vBorder)
import Summoner.Tui.Widget (borderLabel, borderName)
infix 4 |>
(|>) :: Int -> a -> (Int, a)
|> :: Int -> a -> (Int, a)
(|>) = (,)
{-# INLINE (|>) #-}
groupBorder :: String -> [(Int, s -> FormFieldState s e n)] -> [s -> FormFieldState s e n]
groupBorder :: String
-> [(Int, s -> FormFieldState s e n)]
-> [s -> FormFieldState s e n]
groupBorder groupName :: String
groupName = \case
[] -> []
[x :: (Int, s -> FormFieldState s e n)
x] -> [String
-> (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall s e n.
String
-> (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupAllBorders String
groupName (Int, s -> FormFieldState s e n)
x]
(x :: (Int, s -> FormFieldState s e n)
x:y :: (Int, s -> FormFieldState s e n)
y:xs :: [(Int, s -> FormFieldState s e n)]
xs) -> let (mid :: [(Int, s -> FormFieldState s e n)]
mid, l :: (Int, s -> FormFieldState s e n)
l) = (NonEmpty (Int, s -> FormFieldState s e n)
-> [(Int, s -> FormFieldState s e n)]
forall (f :: * -> *) a. IsNonEmpty f a [a] "init" => f a -> [a]
init (NonEmpty (Int, s -> FormFieldState s e n)
-> [(Int, s -> FormFieldState s e n)])
-> NonEmpty (Int, s -> FormFieldState s e n)
-> [(Int, s -> FormFieldState s e n)]
forall a b. (a -> b) -> a -> b
$ (Int, s -> FormFieldState s e n)
y (Int, s -> FormFieldState s e n)
-> [(Int, s -> FormFieldState s e n)]
-> NonEmpty (Int, s -> FormFieldState s e n)
forall a. a -> [a] -> NonEmpty a
:| [(Int, s -> FormFieldState s e n)]
xs, NonEmpty (Int, s -> FormFieldState s e n)
-> (Int, s -> FormFieldState s e n)
forall (f :: * -> *) a. IsNonEmpty f a a "last" => f a -> a
last (NonEmpty (Int, s -> FormFieldState s e n)
-> (Int, s -> FormFieldState s e n))
-> NonEmpty (Int, s -> FormFieldState s e n)
-> (Int, s -> FormFieldState s e n)
forall a b. (a -> b) -> a -> b
$ (Int, s -> FormFieldState s e n)
y (Int, s -> FormFieldState s e n)
-> [(Int, s -> FormFieldState s e n)]
-> NonEmpty (Int, s -> FormFieldState s e n)
forall a. a -> [a] -> NonEmpty a
:| [(Int, s -> FormFieldState s e n)]
xs) in
String
-> (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall s e n.
String
-> (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupBorderTop String
groupName (Int, s -> FormFieldState s e n)
x (s -> FormFieldState s e n)
-> [s -> FormFieldState s e n] -> [s -> FormFieldState s e n]
forall a. a -> [a] -> [a]
: ((Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n)
-> [(Int, s -> FormFieldState s e n)]
-> [s -> FormFieldState s e n]
forall a b. (a -> b) -> [a] -> [b]
map (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall s e n.
(Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupBorderMid [(Int, s -> FormFieldState s e n)]
mid [s -> FormFieldState s e n]
-> [s -> FormFieldState s e n] -> [s -> FormFieldState s e n]
forall a. [a] -> [a] -> [a]
++ [(Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall s e n.
(Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupBorderBottom (Int, s -> FormFieldState s e n)
l]
groupBorderTop :: String -> (Int, s -> FormFieldState s e n) -> (s -> FormFieldState s e n)
groupBorderTop :: String
-> (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupBorderTop groupName :: String
groupName (i :: Int
i, f :: s -> FormFieldState s e n
f) =
( Int -> Widget n -> Widget n
forall n. Int -> Widget n -> Widget n
vLimit Int
i
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Widget n
forall n. Widget n
tl Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=> Widget n
forall n. Widget n
vBorder) Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+>)
(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 -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+> (Widget n
forall n. Widget n
tr Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=> Widget n
forall n. Widget n
vBorder))
(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
hBorderWithLabel (String -> Widget n
forall n. String -> Widget n
borderName String
groupName) Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=>)
) (Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall n s e.
(Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
@@= s -> FormFieldState s e n
f
groupBorderBottom :: (Int, s -> FormFieldState s e n) -> (s -> FormFieldState s e n)
groupBorderBottom :: (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupBorderBottom (i :: Int
i, f :: s -> FormFieldState s e n
f) =
( Int -> Widget n -> Widget n
forall n. Int -> Widget n -> Widget n
vLimit Int
i
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Widget n
forall n. Widget n
vBorder Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=> Widget n
forall n. Widget n
bl) Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+>)
(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 -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+> (Widget n
forall n. Widget n
vBorder Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=> Widget n
forall n. Widget n
br))
(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 -> Widget n
forall n. Widget n -> Widget n -> Widget n
<=> Widget n
forall n. Widget n
hBorder)
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Padding -> Widget n -> Widget n
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max
) (Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall n s e.
(Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
@@= s -> FormFieldState s e n
f
groupBorderMid :: (Int, s -> FormFieldState s e n) -> (s -> FormFieldState s e n)
groupBorderMid :: (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupBorderMid (i :: Int
i, f :: s -> FormFieldState s e n
f) =
( Int -> Widget n -> Widget n
forall n. Int -> Widget n -> Widget n
vLimit Int
i
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Widget n
forall n. Widget n
vBorder Widget n -> Widget n -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+>)
(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 -> Widget n
forall n. Widget n -> Widget n -> Widget n
<+> Widget n
forall n. Widget n
vBorder)
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Padding -> Widget n -> Widget n
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max
) (Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall n s e.
(Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
@@= s -> FormFieldState s e n
f
groupAllBorders :: String -> (Int, s -> FormFieldState s e n) -> (s -> FormFieldState s e n)
groupAllBorders :: String
-> (Int, s -> FormFieldState s e n) -> s -> FormFieldState s e n
groupAllBorders groupName :: String
groupName (i :: Int
i, f :: s -> FormFieldState s e n
f) =
( Int -> Widget n -> Widget n
forall n. Int -> Widget n -> Widget n
vLimit Int
i
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Widget n -> Widget n
forall n. String -> Widget n -> Widget n
borderLabel String
groupName
(Widget n -> Widget n)
-> (Widget n -> Widget n) -> Widget n -> Widget n
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Padding -> Widget n -> Widget n
forall n. Padding -> Widget n -> Widget n
padRight Padding
Max
) (Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
forall n s e.
(Widget n -> Widget n)
-> (s -> FormFieldState s e n) -> s -> FormFieldState s e n
@@= s -> FormFieldState s e n
f
tl, tr, bl, br :: Widget n
tl :: Widget n
tl = Edges Bool -> Widget n
forall n. Edges Bool -> Widget n
joinableBorder (Bool -> Bool -> Bool -> Bool -> Edges Bool
forall a. a -> a -> a -> a -> Edges a
Edges Bool
False Bool
True Bool
False Bool
True)
tr :: Widget n
tr = Edges Bool -> Widget n
forall n. Edges Bool -> Widget n
joinableBorder (Bool -> Bool -> Bool -> Bool -> Edges Bool
forall a. a -> a -> a -> a -> Edges a
Edges Bool
False Bool
True Bool
True Bool
False)
bl :: Widget n
bl = Edges Bool -> Widget n
forall n. Edges Bool -> Widget n
joinableBorder (Bool -> Bool -> Bool -> Bool -> Edges Bool
forall a. a -> a -> a -> a -> Edges a
Edges Bool
True Bool
False Bool
False Bool
True)
br :: Widget n
br = Edges Bool -> Widget n
forall n. Edges Bool -> Widget n
joinableBorder (Bool -> Bool -> Bool -> Bool -> Edges Bool
forall a. a -> a -> a -> a -> Edges a
Edges Bool
True Bool
False Bool
True Bool
False)