~alcinnz/CatTrap

1a650ede5d026bb6a5653731ff45aa4824abeaed — Adrian Cochrane 1 year, 11 days ago bc72114
Implement utils for computing flexbox-relevant sizes.
1 files changed, 44 insertions(+), 1 deletions(-)

M Graphics/Layout/Flex.hs
M Graphics/Layout/Flex.hs => Graphics/Layout/Flex.hs +44 -1
@@ 2,7 2,8 @@ module Graphics.Layout.Flex(FlexParent(..), FlexChild(..),
    Direction(..), FlexWrapping(..), Justification(..), Alignment(..),
    flexMaxBasis, flexSumBasis, flexWrap) where

import Graphics.Layout.Box (Length, lowerLength)
import Graphics.Layout.Box as B (Length, lowerLength, Size(..), PaddedBox(..),
        maxWidth, width, minWidth, maxHeight, height, minHeight)
import Data.List (intersperse)

data FlexParent a b = FlexParent {


@@ 82,6 83,12 @@ flexWrap self size
        sfr = (rowSize - size)/(Prelude.sum $ map shrink row)
        gfr = (size - rowSize)/(Prelude.sum $ map grow row)

flexRowSize :: (a -> Double) -> [FlexChild a b] -> Double
flexRowSize cb row = maximum $ map (cb . flexInner) row
flexRowsSize :: (a -> Double) -> FlexParent a Double -> Double
flexRowsSize cb FlexParent { crossGap = gap, children = kids } =
    sum $ intersperse gap $ flexRowSize cb `map` kids

justifyOffset, justifySpacing :: Double -> [Double] -> Double -> Justification -> Double
justifyOffset _ _ _ JStart = 0
justifyOffset outersize ks g JEnd = outersize - innersize g ks


@@ 106,3 113,39 @@ innersize gap = sum . intersperse gap
half = (/2)
length' :: [a] -> Double
length' = toEnum . length

------
--- Mapping Box Model axes <-> Flex Box axes
------

outerMinMain, outerMain, outerMaxMain :: Num m => PaddedBox m m -> Direction -> m
outerMinMain box Row = minWidth box
outerMinMain box Column = minHeight box
outerMain box Row = width box
outerMain box Column = height box
outerMaxMain box Row = maxWidth box
outerMaxMain box Column = maxHeight box

outerMinCross, outerCross, outerMaxCross :: Num m => PaddedBox m m -> Direction -> m
outerMinCross box Row = minHeight box
outerMinCross box Column = minWidth box
outerCross box Row = height box
outerCross box Column = width box
outerMaxCross box Row = maxHeight box
outerMaxCross box Column = maxWidth box

innerMinMain, innerMain, innerMaxMain :: Num m => PaddedBox m m -> Direction -> m
innerMinMain box = innerMain' $ B.min box
innerMain box = innerMain' $ B.size box
innerMaxMain box = innerMain' $ B.max box

innerMinCross, innerCross, innerMaxCross :: Num m => PaddedBox m m -> Direction -> m
innerMinCross box = innerCross' $ B.min box
innerCross box = innerCross' $ B.size box
innerMaxCross box = innerCross' $ B.max box

innerMain', innerCross' :: Num m => Size m m -> Direction -> m
innerMain' self Row = inline self
innerMain' self Column = block self
innerCross' self Row = block self
innerCross' self Column = inline self