~alcinnz/CatTrap

0ed151bbaad0745a8f59b769bfe7e79eef347e40 — Adrian Cochrane 1 year, 5 months ago 1fb004f
Tidyup: full-size computation from gridcell size computations.
2 files changed, 36 insertions(+), 49 deletions(-)

M Graphics/Layout.hs
M Graphics/Layout/Grid.hs
M Graphics/Layout.hs => Graphics/Layout.hs +8 -8
@@ 78,7 78,7 @@ boxMinWidth parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
boxMinWidth parent (LayoutGrid val self cells0 childs) = LayoutGrid val self' cells' childs'
  where
    self' = self { colMins = cells }
    (_, cells) = gridMinWidths parent' self cells''
    cells = gridMinWidths parent' self cells''
    cells'' = [ setCellBox (mapX' (lowerLength selfWidth) $ gridItemBox cell) cell
                | cell <- cells']
    cells' = map setCellBox' $ zip childs' cells0


@@ 106,7 106,7 @@ boxNatWidth parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
boxNatWidth parent (LayoutGrid val self cells0 childs) = LayoutGrid val self' cells' childs'
  where
    self' = self { colNats = cells }
    (_, cells) = gridNatWidths parent' self cells''
    cells = gridNatWidths parent' self cells''
    cells'' = [
        cell { gridItemBox = mapX' (lowerLength selfWidth) $ gridItemBox cell }
        | cell <- cells']


@@ 149,7 149,7 @@ boxWidth parent (LayoutGrid val self cells childs) = LayoutGrid val self' cells'
    recurse (cell, child) = (cell', child')
      where
        cell' = cell { gridItemBox = layoutGetBox child' }
        child' = boxWidth (mapX' (lowerLength size') $ gridItemBox cell) child
        child' = boxWidth (mapX' (lowerLength outerwidth) $ gridItemBox cell) child
    self' = Grid {
        gap = mapSizeX (lowerLength outerwidth) $ gap self,
        columns = map Left widths,


@@ 160,7 160,7 @@ boxWidth parent (LayoutGrid val self cells childs) = LayoutGrid val self' cells'
        subgridRows = subgridRows self, subgridColumns = subgridColumns self
      }
    outerwidth = inline $ size parent
    (size', widths) = gridWidths parent self (colMins self) (colNats self)
    widths = gridWidths parent self (colMins self) (colNats self)
boxWidth parent (LayoutInline val font (Paragraph a b c d) paging vals) =
    LayoutInline val font (Paragraph a b c d { paragraphMaxWidth = round width }) paging vals
  where width = B.inline $ B.size parent


@@ 178,7 178,7 @@ boxNatHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self cel
  where
    lowerGridUnit (Left length) = Left $ lowerLength width length
    lowerGridUnit (Right x) = Right x
    (_, heights) = gridNatHeights parent self cells'
    heights = gridNatHeights parent self cells'
    cells' = [setCellBox (mapY' (lowerLength width) $ gridItemBox cell) cell | cell <- cells0]
    cells0 = map setCellBox' $ zip childs' cells
    childs' = map (boxNatHeight width) childs


@@ 200,7 200,7 @@ boxMinHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self' ce
        cell' = setCellBox (layoutGetBox child') cell
        child' = boxMinHeight width child
    self' = self { rowMins = heights }
    (_, heights) = gridMinHeights width self childs0
    heights = gridMinHeights width self childs0
    childs0 = [ GridItem {
        gridItemBox = mapY' (lowerLength width) $ gridItemBox cell,
        startRow = startRow cell, endRow = endRow cell,


@@ 225,7 225,7 @@ boxMaxHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self cel
      where
        cell' = setCellBox (layoutGetBox child') cell
        child' = boxMaxHeight (mapY' (lowerLength width) $ gridItemBox cell) child
    (_, heights) = gridMaxHeights parent self (rowMins self) (rowNats self)
    heights = gridMaxHeights parent self (rowMins self) (rowNats self)
    width = inline $ size parent
boxMaxHeight parent (LayoutInline val font self' paging vals) =
    LayoutInline val font self' paging vals


@@ 255,7 255,7 @@ boxHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self' cells
        columns = columns self, colMins = colMins self, colNats = colNats self,
        subgridRows = subgridRows self, subgridColumns = subgridColumns self
      }
    (_, heights) = gridHeights parent self (rowMins self) (rowNats self)
    heights = gridHeights parent self (rowMins self) (rowNats self)
    lowerSize (Left x) = Left $ lowerLength width x
    lowerSize (Right x) = Right x
    width = inline $ size parent

M Graphics/Layout/Grid.hs => Graphics/Layout/Grid.hs +28 -41
@@ 80,38 80,33 @@ verifyGrid self childs = and [
    height = length $ rows self

gridEstWidth :: Grid b Length -> [GridItem y Double] -> Double
gridEstWidth self childs = fst $ gridMaxWidths zeroBox self mins nats
gridEstWidth self childs = sum $ intersperse (lowerLength 0 $ inline $ gap self) maxs
  where
    mins = snd $ gridMinWidths 0 self childs
    nats = snd $ gridNatWidths 0 self childs
gridMinWidths :: Double -> Grid b Length -> [GridItem y Double] -> (Double, [Double])
gridMinWidths parent self childs =
    (sum $ intersperse (lowerLength parent $ inline $ gap self) ret, ret)
    maxs = gridMaxWidths zeroBox self mins nats
    mins = gridMinWidths 0 self childs
    nats = gridNatWidths 0 self childs
gridMinWidths :: Double -> Grid b Length -> [GridItem y Double] -> [Double]
gridMinWidths parent self childs = map colMinWidth $ enumerate $ columns self
  where
    ret = map colMinWidth $ enumerate $ columns self
    colMinWidth (_, Left (Pixels x)) = x
    colMinWidth (_, Left (Percent x)) = x * parent
    colMinWidth arg@(ix, Left Preferred) =
        maximum $ (0:) $ map (inline . size . gridItemBox) $ cellsForCol childs ix
    colMinWidth (ix, _) =
        maximum $ (0:) $ map (inline . B.min . gridItemBox) $ cellsForCol childs ix
gridNatWidths :: Double -> Grid b Length -> [GridItem y Double] -> (Double, [Double])
gridNatWidths parent self childs =
    (sum $ intersperse (lowerLength parent $ inline $ gap self) ret, ret)
gridNatWidths :: Double -> Grid b Length -> [GridItem y Double] -> [Double]
gridNatWidths parent self childs = map colNatWidth $ enumerate $ columns self
  where
    ret = map colNatWidth $ enumerate $ columns self
    colNatWidth (_, Left (Pixels x)) = x
    colNatWidth (_, Left (Percent x)) = x * parent
    colNatWidth arg@(ix, Left Min) =
        maximum $ (0:) $ map (inline . B.min . gridItemBox) $ cellsForCol childs ix
    colNatWidth (ix, _) =
        maximum $ (0:) $ map (inline . size . gridItemBox) $ cellsForCol childs ix
gridMaxWidths :: PaddedBox b Double -> Grid y Length -> [Double] -> [Double] -> (Double, [Double])
gridMaxWidths parent self submins subnats =
    (sum $ intersperse (lowerLength outerwidth $ inline $ gap self) ret, ret)
gridMaxWidths :: PaddedBox b Double -> Grid y Length -> [Double] -> [Double] -> [Double]
gridMaxWidths parent self submins subnats = map (colMaxWidth fr) $ zip subwidths $ columns self
  where
    subwidths = zip submins subnats
    ret = map (colMaxWidth fr) $ zip subwidths $ columns self
    fr = Prelude.max 0 fr'
    fr' = (outerwidth - estimate)/(countFRs $ columns self)
    outerwidth = inline $ size parent


@@ 123,12 118,10 @@ gridMaxWidths parent self submins subnats =
    colMaxWidth _ ((min, _), Left Min) = min
    colMaxWidth fr (_, Left Auto) = fr
    colMaxWidth fr (_, Right x) = x*fr
gridWidths :: PaddedBox b Double -> Grid y Length -> [Double] -> [Double] -> (Double, [Double])
gridWidths parent self submins subnats =
    (sum $ intersperse (lowerLength outerwidth $ inline $ gap self) ret, ret)
gridWidths :: PaddedBox b Double -> Grid y Length -> [Double] -> [Double] -> [Double]
gridWidths parent self submins subnats = map (colWidth fr) $ zip subwidths $ columns self
  where
    subwidths = zip submins subnats
    ret = map (colWidth fr) $ zip subwidths $ columns self
    fr = (outerwidth - estimate)/(countFRs $ columns self)
    outerwidth = inline $ size parent
    estimate = sum $ intersperse (lowerLength outerwidth $ inline $ gap self) $


@@ 141,34 134,28 @@ gridWidths parent self submins subnats =
    colWidth' fr ((_, nat), Left Auto) = Prelude.min nat fr
    colWidth' fr (_, Right x) = x*fr

gridNatHeights :: Double -> Grid Length Double -> [GridItem Double Double] -> (Double, [Double])
gridNatHeights parent self childs =
    (sum $ intersperse (lowerLength parent $ block $ gap self) ret, ret)
gridNatHeights :: Double -> Grid Length Double -> [GridItem Double Double] -> [Double]
gridNatHeights parent self childs = map rowNatHeight $ enumerate $ rows self
  where
    ret = map rowNatHeight $ enumerate $ rows self
    rowNatHeight (_, Left (Pixels x)) = x
    rowNatHeight (_, Left (Percent x)) = x * parent
    rowNatHeight arg@(ix, Left Min) =
        maximum $ (0:) $ map (block . B.min . gridItemBox) $ cellsForCol childs ix
    rowNatHeight (ix, _) =
        maximum $ (0:) $ map (block . size . gridItemBox) $ cellsForCol childs ix
gridMinHeights :: Double -> Grid Length Double -> [GridItem Double Double] -> (Double, [Double])
gridMinHeights parent self childs =
    (sum $ intersperse (lowerLength parent $ block $ gap self) ret, ret)
gridMinHeights :: Double -> Grid Length Double -> [GridItem Double Double] -> [Double]
gridMinHeights parent self childs = map rowMinHeight $ enumerate $ rows self
  where
    ret = map rowMinHeight $ enumerate $ rows self
    rowMinHeight (_, Left (Pixels x)) = x
    rowMinHeight (_, Left (Percent x)) = x * parent
    rowMinHeight arg@(ix, Left Preferred) =
        maximum $ (0:) $ map (block . size . gridItemBox) $ cellsForCol childs ix
    rowMinHeight (ix, _) =
        maximum $ (0:) $ map (block . B.min . gridItemBox) $ cellsForCol childs ix
gridMaxHeights :: PaddedBox Double Double -> Grid Length Double ->
    [Double] -> [Double] -> (Double, [Double])
gridMaxHeights parent self submins subnats = (sum $ intersperse (inline $ gap self) ret, ret)
gridMaxHeights :: PaddedBox Double Double -> Grid Length Double -> [Double] -> [Double] -> [Double]
gridMaxHeights parent self submins subnats = map (colMaxHeight fr) $ zip subheights $ rows self
  where
    subheights = zip submins subnats
    ret = map (colMaxHeight fr) $ zip subheights $ rows self
    fr = (outerheight - estimate)/(countFRs $ rows self)
    outerwidth = inline $ size parent
    outerheight = block $ size parent


@@ 180,12 167,10 @@ gridMaxHeights parent self submins subnats = (sum $ intersperse (inline $ gap se
    colMaxHeight _ ((min, _), Left Min) = min
    colMaxHeight fr (_, Left Auto) = fr
    colMaxHeight fr (_, Right x) = x*fr
gridHeights :: PaddedBox Double Double -> Grid Length Double ->
    [Double] -> [Double] -> (Double, [Double])
gridHeights parent self submins subnats = (sum $ intersperse (inline $ gap self) ret, ret)
gridHeights :: PaddedBox Double Double -> Grid Length Double -> [Double] -> [Double] -> [Double]
gridHeights parent self submins subnats = map (colHeight fr) $ zip subheights $ rows self
  where
    subheights = zip submins subnats
    ret = map (colHeight fr) $ zip subheights $ rows self
    fr = (outerheight - estimate)/(countFRs $ rows self)
    outerwidth = inline $ size parent
    outerheight = block $ size parent


@@ 234,18 219,20 @@ gridLayout parent self childs paginate = (self', zip positions childs)
      }
    Size gapX gapY = gap self

    (height', rows') = gridHeights parent self0 rowMins' rowNats'
    (_, rowMins') = gridMinHeights width' self0 childs
    (_, rowNats') = gridNatHeights width' self0 childs
    height' = gridNatHeight (lowerLength $ block $ B.size parent) self0
    rows' = gridHeights parent self0 rowMins' rowNats'
    rowMins' = gridMinHeights width' self0 childs
    rowNats' = gridNatHeights width' self0 childs

    self0 = self {
        columns = map Left cols',
        colMins = colMins', colNats = colNats',
        gap = Size (lowerLength width' gapX) gapY
      }
    (width', cols') = gridWidths parent self colMins' colNats'
    (_, colMins') = gridMinWidths estWidth self childs
    (_, colNats') = gridNatWidths estWidth self childs
    width' = gridNatWidth (lowerLength $ inline $ B.size parent) self
    cols' = gridWidths parent self colMins' colNats'
    colMins' = gridMinWidths estWidth self childs
    colNats' = gridNatWidths estWidth self childs
    estWidth = gridEstWidth self childs

enumerate = zip [0..]