{-# LANGUAGE DeriveFunctor #-}
module Text.Layout.Table.Primitives.CellMod where

-- | Provide all the information necessary to compare resulting dimensions and
-- to turn it into a 'StringBuilder'.
data CellMod a =
    CellMod
    { forall a. CellMod a -> a
baseCellCM :: a
    , forall a. CellMod a -> Int
leftAdjustmentCM :: Int
    , forall a. CellMod a -> Int
rightAdjustmentCM :: Int
    , forall a. CellMod a -> Int
leftCutMarkLenCM :: Int
    , forall a. CellMod a -> Int
rightCutMarkLenCM :: Int
    } deriving (CellMod a -> CellMod a -> Bool
(CellMod a -> CellMod a -> Bool)
-> (CellMod a -> CellMod a -> Bool) -> Eq (CellMod a)
forall a. Eq a => CellMod a -> CellMod a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CellMod a -> CellMod a -> Bool
$c/= :: forall a. Eq a => CellMod a -> CellMod a -> Bool
== :: CellMod a -> CellMod a -> Bool
$c== :: forall a. Eq a => CellMod a -> CellMod a -> Bool
Eq, Eq (CellMod a)
Eq (CellMod a)
-> (CellMod a -> CellMod a -> Ordering)
-> (CellMod a -> CellMod a -> Bool)
-> (CellMod a -> CellMod a -> Bool)
-> (CellMod a -> CellMod a -> Bool)
-> (CellMod a -> CellMod a -> Bool)
-> (CellMod a -> CellMod a -> CellMod a)
-> (CellMod a -> CellMod a -> CellMod a)
-> Ord (CellMod a)
CellMod a -> CellMod a -> Bool
CellMod a -> CellMod a -> Ordering
CellMod a -> CellMod a -> CellMod a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (CellMod a)
forall a. Ord a => CellMod a -> CellMod a -> Bool
forall a. Ord a => CellMod a -> CellMod a -> Ordering
forall a. Ord a => CellMod a -> CellMod a -> CellMod a
min :: CellMod a -> CellMod a -> CellMod a
$cmin :: forall a. Ord a => CellMod a -> CellMod a -> CellMod a
max :: CellMod a -> CellMod a -> CellMod a
$cmax :: forall a. Ord a => CellMod a -> CellMod a -> CellMod a
>= :: CellMod a -> CellMod a -> Bool
$c>= :: forall a. Ord a => CellMod a -> CellMod a -> Bool
> :: CellMod a -> CellMod a -> Bool
$c> :: forall a. Ord a => CellMod a -> CellMod a -> Bool
<= :: CellMod a -> CellMod a -> Bool
$c<= :: forall a. Ord a => CellMod a -> CellMod a -> Bool
< :: CellMod a -> CellMod a -> Bool
$c< :: forall a. Ord a => CellMod a -> CellMod a -> Bool
compare :: CellMod a -> CellMod a -> Ordering
$ccompare :: forall a. Ord a => CellMod a -> CellMod a -> Ordering
Ord, Int -> CellMod a -> ShowS
[CellMod a] -> ShowS
CellMod a -> String
(Int -> CellMod a -> ShowS)
-> (CellMod a -> String)
-> ([CellMod a] -> ShowS)
-> Show (CellMod a)
forall a. Show a => Int -> CellMod a -> ShowS
forall a. Show a => [CellMod a] -> ShowS
forall a. Show a => CellMod a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CellMod a] -> ShowS
$cshowList :: forall a. Show a => [CellMod a] -> ShowS
show :: CellMod a -> String
$cshow :: forall a. Show a => CellMod a -> String
showsPrec :: Int -> CellMod a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> CellMod a -> ShowS
Show, (forall a b. (a -> b) -> CellMod a -> CellMod b)
-> (forall a b. a -> CellMod b -> CellMod a) -> Functor CellMod
forall a b. a -> CellMod b -> CellMod a
forall a b. (a -> b) -> CellMod a -> CellMod b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> CellMod b -> CellMod a
$c<$ :: forall a b. a -> CellMod b -> CellMod a
fmap :: forall a b. (a -> b) -> CellMod a -> CellMod b
$cfmap :: forall a b. (a -> b) -> CellMod a -> CellMod b
Functor)

-- | Describe a padding operation on the left side.  The padding may not be
-- negative.
padCellLeft :: Int -> a -> CellMod a
padCellLeft :: forall a. Int -> a -> CellMod a
padCellLeft Int
leftPadding = Int -> Int -> a -> CellMod a
forall a. Int -> Int -> a -> CellMod a
modifyCell Int
leftPadding Int
0

-- | Describe a padding operation on the right side.  The padding may not be
-- negative.
padCellRight :: Int -> a -> CellMod a
padCellRight :: forall a. Int -> a -> CellMod a
padCellRight Int
rightPadding = Int -> Int -> a -> CellMod a
forall a. Int -> Int -> a -> CellMod a
modifyCell Int
0 Int
rightPadding

-- | Describe a padding operation.  The padding may not be negative.
padCell :: Int -> Int -> a -> CellMod a
padCell :: forall a. Int -> Int -> a -> CellMod a
padCell Int
leftPadding Int
rightPadding = Int -> Int -> a -> CellMod a
forall a. Int -> Int -> a -> CellMod a
modifyCell Int
leftPadding Int
rightPadding

-- | Describe a trim operation.  None of the arguments may be negative.
trimCell :: Int -> Int -> Int -> Int -> a -> CellMod a
trimCell :: forall a. Int -> Int -> Int -> Int -> a -> CellMod a
trimCell Int
leftTrim Int
rightTrim Int
leftCMLen Int
rightCMLen =
    Int -> Int -> Int -> Int -> a -> CellMod a
forall a. Int -> Int -> Int -> Int -> a -> CellMod a
modifyCellWithCutMarkLen (Int -> Int
forall a. Num a => a -> a
negate Int
leftTrim) (Int -> Int
forall a. Num a => a -> a
negate Int
rightTrim) Int
leftCMLen Int
rightCMLen

-- | Describe a trim operation on the left side.  None of the arguments may be negative.
trimCellLeft :: Int -> Int -> a -> CellMod a
trimCellLeft :: forall a. Int -> Int -> a -> CellMod a
trimCellLeft Int
leftTrim Int
leftCMLen =
    Int -> Int -> Int -> Int -> a -> CellMod a
forall a. Int -> Int -> Int -> Int -> a -> CellMod a
trimCell Int
leftTrim Int
0 Int
leftCMLen Int
0

-- | Describe a trim operation on the right side.  None of the arguments may be negative.
trimCellRight :: Int -> Int -> a -> CellMod a
trimCellRight :: forall a. Int -> Int -> a -> CellMod a
trimCellRight Int
rightTrim Int
rightCMLen =
    Int -> Int -> Int -> Int -> a -> CellMod a
forall a. Int -> Int -> Int -> Int -> a -> CellMod a
trimCell Int
0 Int
rightTrim Int
0 Int
rightCMLen

modifyCellWithCutMarkLen :: Int -> Int -> Int -> Int -> a -> CellMod a
modifyCellWithCutMarkLen :: forall a. Int -> Int -> Int -> Int -> a -> CellMod a
modifyCellWithCutMarkLen Int
la Int
ra Int
lc Int
rc a
c = a -> Int -> Int -> Int -> Int -> CellMod a
forall a. a -> Int -> Int -> Int -> Int -> CellMod a
CellMod a
c Int
la Int
ra Int
lc Int
rc

-- | Given adjustments for the left and the right side, either pad or trim.
-- Negative values will trim, positive values will pad.
modifyCell :: Int -> Int -> a -> CellMod a
modifyCell :: forall a. Int -> Int -> a -> CellMod a
modifyCell Int
la Int
ra = Int -> Int -> Int -> Int -> a -> CellMod a
forall a. Int -> Int -> Int -> Int -> a -> CellMod a
modifyCellWithCutMarkLen Int
la Int
ra Int
0 Int
0

keepCell :: a -> CellMod a
keepCell :: forall a. a -> CellMod a
keepCell = Int -> Int -> Int -> Int -> a -> CellMod a
forall a. Int -> Int -> Int -> Int -> a -> CellMod a
modifyCellWithCutMarkLen Int
0 Int
0 Int
0 Int
0