@@ 10,7 10,7 @@ import Stylist.Tree (StyleTree(..))
import Data.Maybe (fromJust)
import Graphics.Layout.Box as B
-import Graphics.Layout.Grid
+import Graphics.Layout.Grid as Grid
import Graphics.Layout.Flow
import Graphics.Layout
@@ 18,6 18,7 @@ import Graphics.Layout.CSS
import Graphics.Layout.Grid.Table
import Graphics.Layout.Inline.CSS
import Graphics.Layout.CSS.Font (placeholderFont)
+import Graphics.Layout.Flex as Flex
import Data.Text.ParagraphLayout.Rich (constructParagraph,
defaultParagraphOptions, defaultTextOptions,
@@ 360,7 361,7 @@ spec = do
let defaultPageOptions = PageOptions 0 0 2 2
let gridItem x y = GridItem {
cellStart = x, cellEnd = y,
- alignment = Start,
+ Grid.alignment = Start,
minSize = 0, natSize = 0
}
let track cells' = Track {
@@ 410,6 411,366 @@ spec = do
LayoutFlow () lengthBox [inline "H"]
]
]
+ describe "Flexbox" $ do
+ it "wraps properly" $ do
+ let child l = FlexChild {
+ grow = 0,
+ shrink = 0,
+ basis = l,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ }
+ let baseFlex = FlexParent {
+ direction = Row,
+ reverseRows = False,
+ wrap = NoWrap,
+ justify = JStart,
+ alignLines = Just JStart,
+ baseGap = 2,
+ crossGap = 2,
+ Flex.children = [[(child 10) { grow = 1 }, (child 20) { shrink = 1 },
+ (child 30) { grow = 2 }, (child 40) { shrink = 2 }]],
+ pageWidth = 0
+ } :: FlexParent () Double
+ -- These test results don't look right...
+ flexWrap baseFlex 50 `shouldBe` baseFlex {
+ Flex.children = [[(child 10) { grow = 1 },
+ (child 1.3333333333333321) { shrink = 1 }, (child 30) { grow = 2 },
+ (child 2.6666666666666643) { shrink = 2}]]
+ }
+ flexWrap baseFlex 40 `shouldBe` baseFlex {
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -2) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -4) { shrink = 2}]]
+ }
+ flexWrap baseFlex 30 `shouldBe` baseFlex {
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -5.333333333333332) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -10.666666666666664) { shrink = 2}]]
+ }
+ flexWrap baseFlex 20 `shouldBe` baseFlex {
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -8.666666666666668) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -17.333333333333336) { shrink = 2}]]
+ }
+ flexWrap baseFlex 10 `shouldBe` baseFlex {
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -12) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -24) { shrink = 2}]]
+ }
+ flexWrap baseFlex { direction = Flex.Column } 50 `shouldBe` baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child 1.3333333333333321) { shrink = 1 }, (child 30) { grow = 2 },
+ (child 2.6666666666666643) { shrink = 2}]]
+ }
+ flexWrap baseFlex { direction = Flex.Column } 40 `shouldBe` baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -2) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -4) { shrink = 2}]]
+ }
+ flexWrap baseFlex { direction = Flex.Column } 30 `shouldBe` baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -5.333333333333332) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -10.666666666666664) { shrink = 2}]]
+ }
+ flexWrap baseFlex { direction = Flex.Column } 20 `shouldBe` baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -8.666666666666668) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -17.333333333333336) { shrink = 2}]]
+ }
+ flexWrap baseFlex { direction = Flex.Column } 10 `shouldBe` baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child $ -12) { shrink = 1 }, (child 30) { grow = 2 },
+ (child $ -24) { shrink = 2}]]
+ }
+ flexWrap baseFlex { reverseRows = True } 50 `shouldBe` baseFlex {
+ reverseRows = True,
+ Flex.children = [[
+ FlexChild {
+ grow = 0.0,
+ shrink = 2.0,
+ basis = 2.6666666666666643,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 2.0,
+ shrink = 0.0,
+ basis = 30.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 0.0,
+ shrink = 1.0,
+ basis = 1.3333333333333321,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 1.0,
+ shrink = 0.0,
+ basis = 10.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ }
+ ]]
+ }
+ flexWrap baseFlex { reverseRows = True } 40 `shouldBe` baseFlex {
+ reverseRows = True,
+ Flex.children = [[
+ FlexChild {
+ grow = 0.0,
+ shrink = 2.0,
+ basis = -4,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 2.0,
+ shrink = 0.0,
+ basis = 30.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 0.0,
+ shrink = 1.0,
+ basis = -2,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 1.0,
+ shrink = 0.0,
+ basis = 10.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ }
+ ]]
+ }
+ flexWrap baseFlex { reverseRows = True } 30 `shouldBe` baseFlex {
+ reverseRows = True,
+ Flex.children = [[
+ FlexChild {
+ grow = 0.0,
+ shrink = 2.0,
+ basis = -10.666666666666664,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 2.0,
+ shrink = 0.0,
+ basis = 30.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 0.0,
+ shrink = 1.0,
+ basis = -5.333333333333332,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 1.0,
+ shrink = 0.0,
+ basis = 10.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ }
+ ]]
+ }
+ flexWrap baseFlex { reverseRows = True } 20 `shouldBe` baseFlex {
+ reverseRows = True,
+ Flex.children = [[
+ FlexChild {
+ grow = 0.0,
+ shrink = 2.0,
+ basis = -17.333333333333336,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 2.0,
+ shrink = 0.0,
+ basis = 30.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 0.0,
+ shrink = 1.0,
+ basis = -8.666666666666668,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 1.0,
+ shrink = 0.0,
+ basis = 10.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ }
+ ]]
+ }
+ flexWrap baseFlex { reverseRows = True } 10 `shouldBe` baseFlex {
+ reverseRows = True,
+ Flex.children = [[
+ FlexChild {
+ grow = 0.0,
+ shrink = 2.0,
+ basis = -24,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 2.0,
+ shrink = 0.0,
+ basis = 30.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 0.0,
+ shrink = 1.0,
+ basis = -12,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ },
+ FlexChild {
+ grow = 1.0,
+ shrink = 0.0,
+ basis = 10.0,
+ Flex.alignment = AlStart,
+ flexInner = ()
+ }
+ ]]
+ }
+ flexWrap baseFlex { wrap = Wrap } 50 `shouldBe` baseFlex {
+ wrap = Wrap,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child 6) { shrink = 1 }, (child 30) { grow = 2 }], [
+ (child 40) { shrink = 2}]]
+ }
+ flexWrap baseFlex { wrap = Wrap } 40 `shouldBe` baseFlex {
+ wrap = Wrap,
+ Flex.children = [[(child 18) { grow = 1 },
+ (child 20) { shrink = 1 }], [(child 40) { grow = 2 }],
+ [(child 40) { shrink = 2}]]
+ }
+ flexWrap baseFlex { wrap = Wrap } 30 `shouldBe` baseFlex {
+ wrap = Wrap,
+ Flex.children = [[(child 10) { grow = 1 },
+ (child 18) { shrink = 1 }], [(child 30) { grow = 2 }],
+ [(child 30) { shrink = 2}]]
+ }
+ flexWrap baseFlex { wrap = Wrap } 20 `shouldBe` baseFlex {
+ wrap = Wrap,
+ Flex.children = [[(child 20) { grow = 1 }],
+ [(child 20) { shrink = 1 }], [(child 30) { grow = 2 }],
+ [(child 20) { shrink = 2}]]
+ }
+ flexWrap baseFlex { wrap = Wrap } 10 `shouldBe` baseFlex {
+ wrap = Wrap,
+ Flex.children = [[(child 10) { grow = 1 }], [(child 10) { shrink = 1 }],
+ [(child 30) { grow = 2 }], [(child 10) { shrink = 2}]]
+ }
+ flexWrap baseFlex { wrap = WrapReverse } 50 `shouldBe` baseFlex {
+ wrap = WrapReverse,
+ Flex.children = [[(child 40) { shrink = 2}], [(child 10) { grow = 1 },
+ (child 6) { shrink = 1 }, (child 30) { grow = 2 }]]
+ }
+ flexWrap baseFlex { wrap = WrapReverse } 40 `shouldBe` baseFlex {
+ wrap = WrapReverse,
+ Flex.children = [[(child 40) { shrink = 2}], [(child 40) { grow = 2 }],
+ [(child 18) { grow = 1 }, (child 20) { shrink = 1 }]]
+ }
+ flexWrap baseFlex { wrap = WrapReverse } 30 `shouldBe` baseFlex {
+ wrap = WrapReverse,
+ Flex.children = [[(child 30) { shrink = 2}], [(child 30) { grow = 2 }],
+ [(child 10) { grow = 1 }, (child 18) { shrink = 1 }]]
+ }
+ flexWrap baseFlex { wrap = WrapReverse } 20 `shouldBe` baseFlex {
+ wrap = WrapReverse,
+ Flex.children = [[(child 20) { shrink = 2}], [(child 30) { grow = 2 }],
+ [(child 20) { shrink = 1 }], [(child 20) { grow = 1 }]]
+ }
+ flexWrap baseFlex { wrap = WrapReverse } 10 `shouldBe` baseFlex {
+ wrap = WrapReverse,
+ Flex.children = [[(child 10) { shrink = 2}], [(child 30) { grow = 2 }],
+ [(child 10) { shrink = 1 }], [(child 10) { grow = 1 }]]
+ }
+ it "Paginates properly" $ do
+ let child l align = FlexChild {
+ grow = 0,
+ shrink = 0,
+ basis = l,
+ Flex.alignment = align,
+ flexInner = l
+ }
+ let baseFlex = FlexParent {
+ direction = Row,
+ reverseRows = False,
+ wrap = Wrap,
+ justify = JStart,
+ alignLines = Just JStart,
+ baseGap = 2,
+ crossGap = 2,
+ Flex.children = [[(child 10 AlStart) { grow = 1 },
+ (child 20 AlCenter) { shrink = 1 },
+ (child 30 AlEnd) { grow = 2 },
+ (child 40 AlStretch) { shrink = 2 }]],
+ pageWidth = 80
+ } :: FlexParent Double Double
+ let self = flexWrap baseFlex 50
+ self `shouldBe` baseFlex {
+ Flex.children = [[(child 10 AlStart) { grow = 1 },
+ (child 6 AlCenter) { shrink = 1, flexInner = 20 },
+ (child 30 AlEnd) { grow = 2 }], [
+ (child 40 AlStretch) { shrink = 2}]]
+ }
+ flexSplit (\x -> Size x x) 30 50 self `shouldBe` (baseFlex {
+ Flex.children = [[(child 10 AlStart) { grow = 1 },
+ (child 6 AlCenter) { shrink = 1, flexInner = 20 },
+ (child 30 AlEnd) { grow = 2 }]]
+ }, baseFlex {
+ Flex.children = [[(child 40 AlStretch) { shrink = 2}]]
+ })
+ print self { direction = Flex.Column }
+ flexSplit (\x -> Size x x) 40 50 self { direction = Flex.Column } `shouldBe` (baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10 AlStart) { grow = 1 },
+ (child (-4) AlCenter) { shrink = 1, flexInner = 20 },
+ (child 30 AlEnd) { grow = 2 }], [(child 40 AlStretch) { shrink = 2}]]
+ }, baseFlex {
+ direction = Flex.Column,
+ Flex.children = []
+ })
+ flexSplit (\x -> Size x x) 10 50 self { direction = Flex.Column } `shouldBe` (baseFlex {
+ direction = Flex.Column,
+ Flex.children = []
+ }, baseFlex {
+ direction = Flex.Column,
+ Flex.children = [[(child 10 AlStart) { grow = 1 },
+ (child 6 AlCenter) { shrink = 1, flexInner = 20 },
+ (child 30 AlEnd) { grow = 2 }], [(child 40 AlStretch) { shrink = 2}]]
+ })
+ flexSplit (\x -> Size x x) 10 50 self { direction = Flex.Column, pageWidth = 40 } `shouldBe` (baseFlex {
+ Flex.children = [[(child 10 AlStart) { grow = 1 },
+ (child 6 AlCenter) { shrink = 1, flexInner = 20 },
+ (child 30 AlEnd) { grow = 2 }]],
+ pageWidth = 40
+ }, baseFlex {
+ Flex.children = [[(child 40 AlStretch) { shrink = 2}]],
+ pageWidth = 40
+ })
runMath = flip evalCalc [] . mapCalc fst . flip parseCalc [] . filter (/= Whitespace) . tokenize