module Data.Text.ParagraphLayout.Internal.AncestorBox
( AncestorBox (..)
, totalLeftSpacing
, totalRightSpacing
)
where
import Data.Int (Int32)
import Data.Maybe (catMaybes)
-- | Describes the relationship of a fragment to an inline box that contains it.
--
-- A box can have many fragments, and a fragment contained by a box is also
-- contained by all ancestors of that box.
--
-- The root inline box, which forms the basis of each paragraph, is implied
-- and not described by this type of record.
data AncestorBox d = AncestorBox
{ boxUserData :: d
-- ^ User-defined data associated with the inline box.
, boxLeftSpacing :: Maybe Int32
-- ^ `Just` an amount of empty space to add to the left side
-- of the fragment on account of this inline box, or `Nothing`
-- if this is not the leftmost fragment of this inline box.
--
-- Equal to `boxStartSpacing` for LTR boxes.
--
-- Equal to `boxEndSpacing` for RTL boxes.
, boxRightSpacing :: Maybe Int32
-- ^ `Just` an amount of empty space to add to the right side
-- of the fragment on account of this inline box, or `Nothing`
-- if this is not the rightmost fragment of this inline box.
--
-- Equal to `boxStartSpacing` for RTL boxes.
--
-- Equal to `boxEndSpacing` for LTR boxes.
, boxStartSpacing :: Maybe Int32
-- ^ `Just` an amount of empty space to add to the start side
-- of the fragment on account of this inline box, or `Nothing`
-- if this is not the startmost fragment of this inline box.
--
-- Equal to `boxLeftSpacing` for LTR boxes.
--
-- Equal to `boxRightSpacing` for RTL boxes.
, boxEndSpacing :: Maybe Int32
-- ^ `Just` an amount of empty space to add to the end side
-- of the fragment on account of this inline box, or `Nothing`
-- if this is not the endmost fragment of this inline box.
--
-- Equal to `boxLeftSpacing` for RTL boxes.
--
-- Equal to `boxRightSpacing` for LTR boxes.
}
deriving (Eq, Read, Show)
-- | Amount of empty space to add to the left side
-- on account of all given boxes in sum.
totalLeftSpacing :: [AncestorBox d] -> Int32
totalLeftSpacing bs = sum $ catMaybes $ map boxLeftSpacing bs
-- | Amount of empty space to add to the right side
-- on account of all given boxes in sum.
totalRightSpacing :: [AncestorBox d] -> Int32
totalRightSpacing bs = sum $ catMaybes $ map boxRightSpacing bs