~alcinnz/CatTrap

9b179cc5c695821553aadec9f35d2c9335325b26 — Adrian Cochrane 1 year, 7 months ago a5de823
Don't parse unimplemented subgrids, add notes as to how to implement.
3 files changed, 18 insertions(+), 33 deletions(-)

M Graphics/Layout.hs
M Graphics/Layout/Grid/CSS.hs
M app/Main.hs
M Graphics/Layout.hs => Graphics/Layout.hs +9 -10
@@ 81,9 81,8 @@ boxMinWidth parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
boxMinWidth parent (LayoutGrid val self cells0 childs) = LayoutGrid val self' cells' childs'
  where
    self' = Size (inline self) { trackMins = cells } (block self)
    cells = sizeTrackMins parent' (inline self) $ map inline cells''
    cells'' = [ setCellBox cell (gridItemBox self cell) | cell <- cells']
    cells' = map setCellBox' $ zip childs' cells0
    cells = sizeTrackMins parent' (inline self) $ map inline cells'
    cells' = map setCellBox' $ zip childs' cells0 -- Flatten subgrids
    childs'' = map (mapX' $ lowerLength selfWidth) $ map layoutGetBox childs'
    childs' = map (boxMinWidth $ Just selfWidth) childs
    selfWidth = trackNat (lowerLength parent') $ inline self


@@ 107,7 106,7 @@ boxNatWidth parent (LayoutGrid val self cells0 childs) = LayoutGrid val self' ce
  where
    self' = Size (inline self) { trackNats = cells } (block self)
    cells = sizeTrackNats parent' (inline $ self) $ map inline cells'
    cells' = map setCellBox' $ zip childs' cells0
    cells' = map setCellBox' $ zip childs' cells0 -- Flatten subgrids
    childs'' = map (mapX' $ lowerLength selfWidth) $ map layoutGetBox childs'
    childs' = map (boxNatWidth $ Just selfWidth) childs
    selfWidth = trackNat (lowerLength parent') $ inline self


@@ 125,7 124,7 @@ boxMaxWidth parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
    self' = self { B.max = Size (Pixels max') (block $ B.max self) }
    max' = flowMaxWidth parent self
boxMaxWidth parent (LayoutGrid val self cells childs) = LayoutGrid val self cells childs'
  where
  where -- Propagate parent track as default.
    childs' = map inner $ zip cells childs
    inner (Size cellx celly, child) =
        boxMaxWidth (cellSize (inline self) cellx `size2box` cellSize (block self) celly) child


@@ 143,7 142,7 @@ boxWidth parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
      }
    size' = flowWidth parent self
boxWidth parent (LayoutGrid val self cells childs) = LayoutGrid val self' cells' childs'
  where
  where -- Propagate parent track as default
    (cells', childs') = unzip $ map recurse $ zip cells childs
    recurse (cell, child) = (cell', child')
      where


@@ 173,7 172,7 @@ boxNatHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self' ce
  where
    self' = Size (inline self) (block self) { trackNats = heights }
    heights = sizeTrackNats parent (block self) $ map block cells'
    cells' = map setCellBox' $ zip childs' cells
    cells' = map setCellBox' $ zip childs' cells -- Flatten subgrids
    childs' = map (boxNatHeight width) childs
    width = trackNat id $ inline self
boxNatHeight parent self@(LayoutInline _ _ _ _ _) = self


@@ 188,7 187,7 @@ boxMinHeight parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
boxMinHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self' cells' childs'
  where
    (cells', childs') = unzip $ map recurse $ zip cells childs
    recurse (cell, child) = (cell', child')
    recurse (cell, child) = (cell', child') -- Propagate track into subgrids.
      where
        cell' = setCellBox cell (layoutGetBox child')
        child' = boxMinHeight width child


@@ 209,7 208,7 @@ boxMaxHeight parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
boxMaxHeight parent (LayoutGrid val self cells childs) = LayoutGrid val self cells' childs'
  where
    (cells', childs') = unzip $ map recurse $ zip cells childs
    recurse (cell, child) = (cell', child')
    recurse (cell, child) = (cell', child') -- Propagate track into subgrids
      where
        cell' = setCellBox cell (layoutGetBox child')
        child' = boxMaxHeight (gridItemBox self cell) child


@@ 232,7 231,7 @@ boxHeight parent (LayoutFlow val self childs) = LayoutFlow val self' childs'
boxHeight parent (LayoutGrid val self cells0 childs) = LayoutGrid val self' cells' childs'
  where
    (cells', childs') = unzip $ map recurse $ zip cells0 childs
    recurse (cell, child) = (cell', child')
    recurse (cell, child) = (cell', child') -- Propagate track into subgrids.
      where
        cell' = setCellBox cell (layoutGetBox child')
        child' = boxHeight (layoutGetBox $ LayoutGrid val self' [] []) child

M Graphics/Layout/Grid/CSS.hs => Graphics/Layout/Grid/CSS.hs +8 -22
@@ 19,8 19,8 @@ data CSSGrid = CSSGrid {
    autoFlowDense :: Bool,
    autoRows :: Unitted,
    templateAreas :: [[Text]],
    templateColumns :: Either [([Text], Unitted)] [[Text]],
    templateRows :: Either [([Text], Unitted)] [[Text]],
    templateColumns :: [([Text], Unitted)],
    templateRows :: [([Text], Unitted)],
    cssGap :: Size Unitted Unitted,
    alignItems :: Size Alignment Alignment
}


@@ 42,8 42,8 @@ instance PropertyParser CSSGrid where
        autoFlowDense = False,
        autoRows = auto,
        templateAreas = [],
        templateColumns = Left [],
        templateRows = Left [],
        templateColumns = [],
        templateRows = [],
        cssGap = Size (0,"px") (0,"px"),
        alignItems = Size Start Start -- FIXME: Should be stretch, unsupported.
    }


@@ 222,11 222,9 @@ placement [Ident "span", Ident y, Number _ (NVInteger x)]
    | x > 0 = Just $ Span (fromEnum x) (Just y)
placement _ = Nothing

parseTemplate [Ident "none"] = Just $ Left []
parseTemplate [Ident "initial"] = Just $ Left []
parseTemplate toks | (tracks@(_:_), []) <- parseTrack toks = Just $ Left tracks
parseTemplate (Ident "subgrid":toks)
    | (names@(_:_), []) <- parseSubgrid toks = Just $ Right names
parseTemplate [Ident "none"] = Just []
parseTemplate [Ident "initial"] = Just []
parseTemplate toks | (tracks@(_:_), []) <- parseTrack toks = Just tracks
parseTemplate _ = Nothing
parseTrack (LeftSquareBracket:toks)
    | Just (names', toks') <- parseNames toks,


@@ 253,7 251,7 @@ parseNames _ = Nothing
finalizeGrid :: PropertyParser x => CSSGrid -> Font' ->
    [CSSCell] -> [LayoutItem Length Length x] -> LayoutItem Length Length x
finalizeGrid self@CSSGrid {
        templateColumns = Left cols', templateRows = Left rows'
        templateColumns = cols', templateRows = rows'
    } font cells childs = LayoutGrid temp self' cells' childs
  where
    self' = Size Track {


@@ 332,15 330,3 @@ finalizeGrid self@CSSGrid {

    finalizeFR (x,"fr") = Right x
    finalizeFR x = Left $ finalizeLength x font
finalizeGrid self@CSSGrid { templateColumns = Right colnames } font cells childs =
    LayoutGrid val' self' cells' childs' -- TODO support subgrids
  where
    LayoutGrid val' self' cells' childs' = finalizeGrid self {
        templateColumns = Left $ zip colnames $ repeat (1,"fr")
      } font cells childs
finalizeGrid self@CSSGrid { templateRows = Right rownames } font cells childs =
    LayoutGrid val' self' cells' childs' -- TODO support subgrids
  where
    LayoutGrid val' self' cells' childs' = finalizeGrid self {
        templateRows = Left $ zip rownames $ repeat (1,"fr")
      } font cells childs

M app/Main.hs => app/Main.hs +1 -1
@@ 50,7 50,7 @@ main = do
    displayCallback $= do
        clear [ ColorBuffer ]
        Size x y <- get windowSize
        let display = boxLayout zeroBox {
        let (display:_) = boxLayout zeroBox {
            B.size = B.Size (fromIntegral x) (fromIntegral y)
          } layout False