From 272852e8b518fb81dcd92d785f8284a713df0e2b Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Thu, 16 Feb 2023 16:35:06 +1300 Subject: [PATCH] Draft new CatTrap API which hopefully is easier to implement. --- Graphics/Layout.hs | 21 ++++++++++++++------- Graphics/Layout/Box.hs | 28 ++++++++++++++++------------ Graphics/Layout/Flow.hs | 11 ++++++++--- Graphics/Layout/Grid.hs | 30 ++++++++++++++++++------------ cattrap.cabal | 3 +-- 5 files changed, 57 insertions(+), 36 deletions(-) diff --git a/Graphics/Layout.hs b/Graphics/Layout.hs index e8b8cfd..0c0f9da 100644 --- a/Graphics/Layout.hs +++ b/Graphics/Layout.hs @@ -3,12 +3,19 @@ module Graphics.Layout where import Graphics.Layout.Box import Graphics.Layout.Grid -data LayoutItem n x = - LayoutFlow x (PaddedBox n) [LayoutItem n x] - | LayoutGrid x (Grid n) [(GridItem n, LayoutItem n x)] +data LayoutItem m n x = + LayoutFlow x (PaddedBox m n) [LayoutItem m n x] + | LayoutGrid x (Grid m n) [(GridItem m n, LayoutItem m n x)] -- More to come... -{-sizeBound :: LayoutItem Length () -> LayoutItem Length () -size :: PaddedBox Double -> LayoutItem Length () -> LayoutItem Double () -position :: LayoutItem Double -> LayoutItem Double Size -layout :: PaddedBox Double -> LayoutItem Length () -> Bool -> [LayoutItem Double Size]-} +boxMinWidth :: Double -> LayoutItem y Length x -> (Double, LayoutItem y Length x) +boxNatWidth :: Double -> LayoutItem y Length x -> (Double, LayoutItem y Length x) +boxMaxWidth :: PaddedBox y Length -> LayoutItem y Length x -> (Double, LayoutItem y Length x) +boxWidth :: PaddedBox y Length -> LayoutItem y Length x -> (Double, LayoutItem y Double x) +boxNatHeight :: LayoutItem Length Double x -> (Double, LayoutItem Length Double x) +boxMinHeight :: Double -> LayoutItem Length Double x -> (Double, LayoutItem Length Double x) +boxMaxHeight :: Double -> LayoutItem Length Double x -> (Double, LayoutItem Length Double x) +boxHeight :: Double -> LayoutItem Length Double x -> (Double, LayoutItem Length Length x) +boxPosition :: LayoutItem Double Double x -> LayoutItem Double Double x +boxLayout :: PaddedBox Double Double -> LayoutItem Length Length x -> Bool -> + LayoutItem Double Double x diff --git a/Graphics/Layout/Box.hs b/Graphics/Layout/Box.hs index f25d989..8700acd 100644 --- a/Graphics/Layout/Box.hs +++ b/Graphics/Layout/Box.hs @@ -1,22 +1,26 @@ {-# LANGUAGE RecordWildCards #-} module Graphics.Layout.Box where -data Border n = Border { - top :: n, bottom :: n, left :: n, right :: n +data Border m n = Border { + top :: m, bottom :: m, left :: n, right :: n } -data Size n = Size {inline :: n, block :: n} +data Size m n = Size {inline :: n, block :: m} -data PaddedBox n = PaddedBox { - min :: Size n, - max :: Size n, - size :: Size n, - padding :: Border n, - border :: Border n, - margin :: Border n +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 } -width' PaddedBox {..} = left margin + left border + left padding + +width PaddedBox {..} = left margin + left border + left padding + inline size + right padding + right border + right margin -height' PaddedBox {..} = top margin + top border + top padding + +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 data Length = Pixels Double | Percent Double | Auto | Preferred | Min diff --git a/Graphics/Layout/Flow.hs b/Graphics/Layout/Flow.hs index 5e01599..33ffabd 100644 --- a/Graphics/Layout/Flow.hs +++ b/Graphics/Layout/Flow.hs @@ -1,10 +1,15 @@ module Graphics.Layout.Flow where import Graphics.Layout.Box -import Stylist.Tree (StyleTree(..)) -sizeBoundFlow :: PaddedBox Length -> [PaddedBox Length] -> PaddedBox Length -sizeFlow :: PaddedBox Double -> PaddedBox Length -> PaddedBox Double +flowMinWidth :: Double -> PaddedBox Length -> [PaddedBox Length] -> Double +flowNatWidth :: Double -> PaddedBox Length -> [PaddedBox Length] -> Double +flowMaxWidth :: PaddedBox Double -> PaddedBox Length -> Double +flowWidth :: PaddedBox Double -> PaddedBox Length -> Double +flowNatHeight :: PaddedBox Length -> [PaddedBox Double] -> Double +flowMinHeight :: Double -> PaddedBox Double -> Double +flowMaxHeight :: Double -> PaddedBox Double -> Double +flowHeight :: Double -> PaddedBox Double -> Double positionFlow :: PaddedBox Double -> [PaddedBox Double] -> [Size Double] layoutFlow :: PaddedBox Double -> PaddedBox Length -> [PaddedBox Length] -> Bool -> [(PaddedBox Double, [(Size Double, PaddedBox Double)])] diff --git a/Graphics/Layout/Grid.hs b/Graphics/Layout/Grid.hs index 35dfed2..73aabc7 100644 --- a/Graphics/Layout/Grid.hs +++ b/Graphics/Layout/Grid.hs @@ -3,22 +3,28 @@ module Graphics.Layout.Grid where import Data.Text (Text) import Graphics.Layout.Box -data Grid n = Grid { - rows :: [(Name, Either n Double)], +data Grid m n = Grid { + rows :: [(Name, Either m Double)], columns :: [(Name, Either n Double)], - gap :: Size n, - gridBox :: PaddedBox n + gap :: Size m n, + gridBox :: PaddedBox m n } -data GridItem n = GridItem { +data GridItem m n = GridItem { startRow :: Int, endRow :: Int, startCol :: Int, endCol :: Int, - gridItemBox :: PaddedBox n + gridItemBox :: PaddedBox m n } type Name = Text -{-sizeBoundGrid :: Grid Length -> [GridItem Length] -> Grid Length -sizeGrid :: PaddedBox Double -> Grid Length -> Grid Double -sizeGridItem :: Grid Length -> GridItem Length -> Grid Double -positionGrid :: Grid Double -> [GridItem Double] -> [Size] -layoutGrid :: PaddedBox Double -> Grid Length -> [GridItem Length] -> Bool -> - [(Grid Double, [(Size, GridItem Double)])]-} +gridMinWidths :: Double -> Grid y Length -> [GridItem y Length] -> (Double, [Double]) +gridNatWidths :: Double -> Grid y Length -> [GridItem y Length] -> (Double, [Double]) +gridMaxWidths :: PaddedBox y Double -> Grid y Length -> (Double, [Double]) +gridWidths :: PaddedBox y Double -> Grid y Length -> (Double, [Double]) +gridNatHeights :: PaddedBox Length Double -> [GridItem Length Double] -> (Double, [Double]) +gridMinHeights :: Double -> Grid Length Double -> (Double, [Double]) +gridMaxHeights :: Double -> Grid Length Double -> (Double, [Double]) +gridHeights :: Double -> Grid Length Double -> (Double, [Double]) +gridPosition :: GridLength Double Double -> [GridItem Double Double] -> [Size Double Double] +gridLayout :: PaddedBox Double Double -> Grid Length Length -> + [GridItem Length Length] -> Bool -> + (Grid Double Double, [(Size Double Double, GridItem Double Double)]) diff --git a/cattrap.cabal b/cattrap.cabal index 2f23456..5c19ee8 100644 --- a/cattrap.cabal +++ b/cattrap.cabal @@ -17,8 +17,7 @@ extra-source-files: CHANGELOG.md cabal-version: >=1.10 library - exposed-modules: Graphics.Layout, Graphics.Layout.CSS, --- Graphics.Layout.Flow, + exposed-modules: Graphics.Layout, Graphics.Layout.CSS, Graphics.Layout.Flow, Graphics.Layout.Grid, Graphics.Layout.Box, Graphics.Layout.Arithmetic -- other-modules: -- other-extensions: -- 2.30.2