From 9b179cc5c695821553aadec9f35d2c9335325b26 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Sun, 9 Apr 2023 13:23:32 +1200 Subject: [PATCH] Don't parse unimplemented subgrids, add notes as to how to implement. --- Graphics/Layout.hs | 19 +++++++++---------- Graphics/Layout/Grid/CSS.hs | 30 ++++++++---------------------- app/Main.hs | 2 +- 3 files changed, 18 insertions(+), 33 deletions(-) diff --git a/Graphics/Layout.hs b/Graphics/Layout.hs index bee9693..bf5fbf4 100644 --- a/Graphics/Layout.hs +++ b/Graphics/Layout.hs @@ -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 diff --git a/Graphics/Layout/Grid/CSS.hs b/Graphics/Layout/Grid/CSS.hs index f4e2150..89311d7 100644 --- a/Graphics/Layout/Grid/CSS.hs +++ b/Graphics/Layout/Grid/CSS.hs @@ -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 diff --git a/app/Main.hs b/app/Main.hs index 23a14c8..330c722 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -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 -- 2.30.2