{-# LANGUAGE RecordWildCards #-}
module Graphics.Layout.Box where
data Border m n = Border {
top :: m, bottom :: m, left :: n, right :: n
}
mapX :: (n -> nn) -> Border m n -> Border m nn
mapY :: (m -> mm) -> Border m n -> Border mm n
mapX cb self = self { left = cb $ left self, right = cb $ right self }
mapY cb self = self { top = cb $ top self, bottom = cb $ bottom self }
data Size m n = Size {inline :: n, block :: m} deriving (Eq, Show)
data PaddedBox m n = PaddedBox {
min :: Size m n,
max :: Size m n,
size :: Size m n,
padding :: Border m n,
border :: Border m n,
margin :: Border m n
}
zeroBox :: PaddedBox Double Double
zeroBox = PaddedBox {
min = Size 0 0,
max = Size 0 0,
size = Size 0 0,
padding = Border 0 0 0 0,
border = Border 0 0 0 0,
margin = Border 0 0 0 0
}
lengthBox = PaddedBox {
min = Size Auto Auto,
max = Size Auto Auto,
size = Size Auto Auto,
padding = Border zero zero zero zero,
border = Border zero zero zero zero,
margin = Border zero zero zero zero
} where zero = Pixels 0
width PaddedBox {..} = left margin + left border + left padding +
inline size + right padding + right border + right margin
height PaddedBox {..} = top margin + top border + top padding +
block size + bottom padding + bottom border + bottom margin
minWidth PaddedBox {..} = left margin + left border + left padding +
inline min + right padding + right border + right margin
minHeight PaddedBox {..} = top margin + top border + top padding +
block min + bottom padding + bottom border + bottom margin
maxWidth PaddedBox {..} = left margin + left border + left padding +
inline max + right padding + right border + right margin
maxHeight PaddedBox {..} = top margin + top border + top padding +
block max + bottom padding + bottom border + bottom margin
data Length = Pixels Double | Percent Double | Auto | Preferred | Min deriving Eq
lowerLength :: Double -> Length -> Double
lowerLength _ (Pixels x) = x
lowerLength outerwidth (Percent x) = x * outerwidth
lowerLength _ _ = 0