geomancy-layout 0.2.0 → 0.2.1
raw patch · API changes only · 4 files changed · hide whitespace changes · browse geomancy-layout-0.2.1
+288/−78 lines, 4 files
API changes (from Hackage documentation)
No API comparison: Hackage has no documentation for geomancy-layout-0.2.1.
Files
- CHANGELOG.md +18/−0
- geomancy-layout.cabal +1/−1
- src/Geomancy/Layout/View.hs +172/−77
- test/Spec.hs +97/−0 · folded
CHANGELOG.md view
@@ -1,3 +1,21 @@+## 0.2.1++### Midlines++A view can report a midline, the line its content sits on, measured from its top. Toolkits pick that line for their leaves. Text would use the middle of the capitals on its first line. An icon would use the middle of its face.++`GuidedFun` and `guidedFun` make leaves that report one with their size. `LayoutView` has `reportedMidline` for other payloads, and it defaults to none. `suspendGuided` and `decorated` return the midline along with the size. `suspend` keeps its type.++Padding, frames, offsets and spans carry their content's midline. Overlays and backgrounds carry their primary's. Columns, z-stacks and grids take the first one among their children.++A middle-aligned row lines up the midlines of its children. A child without one puts the middle of its box on the line. The row grows above and below the line to fit them all, and reports that line as its own midline. Padding or decoration below text no longer pulls the text off its neighbours' line. A row with no midlines centres its children as before. Top- and bottom-aligned rows ignore midlines.++A middle-aligned grid lines up the cells of each row the same way. SwiftUI's grid rows align on the same guides as its stacks. A row grows to fit its line, and the grid reports its first row's line as its midline. A cell spanning several rows still centres its box. SwiftUI grids can't span rows and offer no rule for it.++### Grid++Tracks ask every cell for its size, including cells that measured as fixed. A cell that reports more than it measured, like a middle-aligned row, stays inside its track instead of spilling into the next one. A grid can now report more height than it measured, the same way a middle-aligned row can.+ ## 0.2.0 Layout follows SwiftUI more closely. Where SwiftUI is silent, it picks the least surprising option.
geomancy-layout.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: geomancy-layout-version: 0.2.0+version: 0.2.1 synopsis: Geometry and matrix manipulation description: Layout primitives and algorithms for geomancy data. category: Graphics
src/Geomancy/Layout/View.hs view
@@ -17,10 +17,10 @@ import Data.Foldable1 (foldMap1') import Data.Traversable (foldMapDefault) import Data.Functor.Identity (Identity)-import Data.List (mapAccumL, foldl', sortOn)+import Data.List (mapAccumL, sortOn, zip4) import Data.List.NonEmpty (nonEmpty) import Data.List.NonEmpty qualified as NonEmpty-import Data.Maybe (fromMaybe)+import Data.Maybe (catMaybes, fromMaybe, isJust, listToMaybe) import Geomancy ((^*)) import Geomancy.Gl.Funs (glClamp) import Geomancy.Layout qualified as Layout@@ -68,6 +68,9 @@ type Placed stuff type Placed stuff = stuff + reportedMidline :: ReportedCache stuff -> Maybe Float+ reportedMidline _cache = Nothing+ -- | Default implementation is "the view *will* adapt to any size" default viewFlexibility :: stuff -> ViewSize viewFlexibility = const infinite_@@ -111,6 +114,22 @@ proposeView size (ViewFun _ f) = f size placeView placed f = f placed +data GuidedFun stuff = GuidedFun ViewSize (Vec2 -> (Vec2, Maybe Float, Box -> stuff))+ deriving (Functor)++guidedFun :: ViewSize -> (Vec2 -> (Vec2, Maybe Float, Box -> stuff)) -> View () (GuidedFun stuff)+guidedFun flex steps = View{ann=(), stuff=GuidedFun flex steps}++instance LayoutView (GuidedFun stuff) where+ type ReportedCache (GuidedFun stuff) = (Maybe Float, Box -> stuff)+ type Placed (GuidedFun stuff) = stuff+ viewFlexibility (GuidedFun vs _) = vs+ proposeView size (GuidedFun _ f) = (reported, (midline, placeReported))+ where+ (reported, midline, placeReported) = f size+ reportedMidline = fst+ placeView placed (_midline, placeReported) = placeReported placed+ -- * View tree {- | Layout skeleton@@ -563,70 +582,76 @@ => Vec2 -> View ViewSize stuff -> (Vec2, Box -> View Box (Placed stuff))-suspend proposed = \case+suspend proposed element = (reported, placeReported)+ where+ (reported, _midline, placeReported) = suspendGuided proposed element++suspendGuided+ :: forall stuff+ . LayoutView stuff+ => Vec2+ -> View ViewSize stuff+ -> (Vec2, Maybe Float, Box -> View Box (Placed stuff))+suspendGuided proposed = \case Spacer{ann} -> ( vsClamp proposed ann proposed- , \placed -> Spacer{ann=placed} -- keep the placed+ , Nothing+ , \placed -> Spacer{ann=placed} ) View{stuff} ->- ( reported -- report dynamic size+ ( reported+ , reportedMidline @stuff cache , \placed -> View { ann = placed- , stuff = placeView @stuff placed cache -- instantiate the placed view+ , stuff = placeView @stuff placed cache } ) where (reported, cache) = proposeView proposed stuff Frame{..} ->- ( size -- frame reports its size right away+ ( size+ , alignedMidline align size reported midline , \placedFrame -> Frame- { ann = placedFrame -- keep the placed for itself- , inner =- let- -- now that the frame has its own box, it can properly place its contents- innerBox = Layout.placeSize align reported placedFrame- in- -- and resolve the continuation- suspended innerBox+ { ann = placedFrame+ , inner = suspended $ Layout.placeSize align reported placedFrame , .. } ) where- (reported, suspended) = suspend size inner -- frame proposes its size+ (reported, midline, suspended) = suspendGuided size inner FlexibleFrame{..} ->- ( framedSize bounds proposed reported+ ( framed+ , alignedMidline align framed reported midline , \placed ->- let- innerBox = Layout.placeSize align reported placed- in- FlexibleFrame- { ann = placed- , inner = suspended innerBox- , ..- }+ FlexibleFrame+ { ann = placed+ , inner = suspended $ Layout.placeSize align reported placed+ , ..+ } ) where- (reported, suspended) = suspend (offeredSize bounds proposed) inner+ framed = framedSize bounds proposed reported+ (reported, midline, suspended) = suspendGuided (offeredSize bounds proposed) inner Padding{..} -> ( reported + pads+ , (+ top) <$> midline , \placed ->- let- innerBox = Box.addPadding trbl placed- in Padding { ann = placed- , inner = suspended innerBox+ , inner = suspended $ Box.addPadding trbl placed , .. } ) where- (reported, suspended) = suspend (proposed - pads) inner+ (reported, midline, suspended) = suspendGuided (proposed - pads) inner pads = withVec4 trbl4 \t r b l -> vec2 (l + r) (t + b)+ top = withVec4 trbl4 \t _r _b _l -> t Box.TRBL trbl4 = trbl Offset{..} -> ( reported+ , midline , \placed -> Offset { ann = placed , inner = suspended $ Box.move xy placed@@ -634,44 +659,53 @@ } ) where- (reported, suspended) = suspend proposed inner+ (reported, midline, suspended) = suspendGuided proposed inner Span{..} -> ( reported+ , midline , \placed -> Span{ann = placed, inner = suspended placed, ..} ) where- (reported, suspended) = suspend proposed inner+ (reported, midline, suspended) = suspendGuided proposed inner AspectRatio{..} ->- ( maybe reported (`coverAspect` reported) ratio+ ( covered+ , alignedMidline align covered reported midline , \placed ->- let- innerBox = Layout.placeSize align reported placed- in AspectRatio { ann = placed- , inner = suspended innerBox+ , inner = suspended $ Layout.placeSize align reported placed , .. } ) where ratio = usableAspect aspect- (reported, suspended) = suspend (maybe proposed (\r -> fitAspect r $ growableRoom inner.ann proposed) ratio) inner+ covered = maybe reported (`coverAspect` reported) ratio+ (reported, midline, suspended) = suspendGuided (maybe proposed (\r -> fitAspect r $ growableRoom inner.ann proposed) ratio) inner HStack{spacing, align, children} ->- -- Like the Frame, but operating on multiple elements- ( vec2 runWidth crossHeight -- stack reports the combined size of its children reports+ ( vec2 runWidth crossHeight+ , stackMidline , \placedStack -> let placedChildren :: [View Box (Placed stuff)] placedChildren = Box.withTRBL (justify placedStack) \t _r b l ->- [ suspended $ Layout.placeSize align reportedSize (Box.fromTRBL t (l + start + w) b (l + start))- | ((reportedSize, suspended), start) <- zip children' starts- , let w = withVec2 reportedSize \w' _h -> w'+ [ suspended $ Layout.placeSize align reportedSize (slot t b (l + start) reportedSize midline)+ | ((reportedSize, midline, suspended), start) <- zip children' starts ] + slot t b left reportedSize midline =+ withVec2 reportedSize \w h ->+ if guided then+ let+ runTop = t + (b - t - crossHeight) * alignY+ childTop = runTop + above - fromMaybe (h * 0.5) midline+ in+ Box.fromTRBL childTop (left + w) (childTop + h) left+ else+ Box.fromTRBL t (left + w) b left+ justify box =- withVec2 alignOrigins \origin _ ->- shiftRun Layout.cutLeft origin (Box.width box - runWidth) box+ shiftRun Layout.cutLeft alignX (Box.width box - runWidth) box in HStack { ann = maybe placedStack (foldMap1' ann) $ nonEmpty placedChildren@@ -682,12 +716,22 @@ ) where Alignment alignOrigins = align+ WithVec2 alignX alignY = alignOrigins slotGaps = rowGaps spacing $ map ann children gaps = sum slotGaps- (starts, runWidth) = runOffsets slotGaps [withVec2 reportedSize \w _h -> w | (reportedSize, _) <- children']- crossHeight = foldl' max 0 [withVec2 reportedSize \_w h -> h | (reportedSize, _) <- children']+ (starts, runWidth) = runOffsets slotGaps [withVec2 reportedSize \w _h -> w | (reportedSize, _, _) <- children'] - -- | Record index, sort by flexibility, process, restore order+ guided = alignY == Alignment.Middle && any (\(_, midline, _) -> isJust midline) children'+ extents = [withVec2 reportedSize \_w h -> let m = fromMaybe (h * 0.5) midline in (m, h - m) | (reportedSize, midline, _) <- children']+ above = foldl' max (-inf) (map fst extents)+ below = foldl' max (-inf) (map snd extents)+ crossHeight+ | guided = above + below+ | otherwise = foldl' max 0 [withVec2 reportedSize \_w h -> h | (reportedSize, _, _) <- children']+ stackMidline+ | guided = Just above+ | otherwise = firstJust [alignedMidline align (vec2 0 crossHeight) reportedSize midline | (reportedSize, midline, _) <- children']+ children' = toList . array (0, numChildren - 1) $ snd $ mapAccumL f (fromIntegral numChildren, budget) $ zip (reservedAfter minWidthOf sorted) sorted@@ -698,24 +742,22 @@ f (childrenRemaining, WithVec2 remW remH) (reserved, (ix, child)) = ( (childrenRemaining - 1.0, vec2 (max 0 $ remW - reportedWidth) remH)- , ( ix- , child'- ) -- XXX: can use combineH here+ , (ix, child') ) where- WithVec2 reportedWidth _ = fst child'- child' = suspend (vec2 proposeWidth remH) child+ (WithVec2 reportedWidth _, _, _) = child'+ child' = suspendGuided (vec2 proposeWidth remH) child proposeWidth = fairShare (minWidthOf child) reserved remW childrenRemaining VStack{spacing, align, children} ->- -- Like the HStack, but advancing vertically ( vec2 crossWidth runHeight+ , firstJust [(+ start) <$> midline | ((_, midline, _), start) <- zip children' starts] , \placedStack -> let placedChildren :: [View Box (Placed stuff)] placedChildren = Box.withTRBL (justify placedStack) \t r _b l -> [ suspended $ Layout.placeSize align reportedSize (Box.fromTRBL (t + start) r (t + start + h) l)- | ((reportedSize, suspended), start) <- zip children' starts+ | ((reportedSize, _, suspended), start) <- zip children' starts , let h = withVec2 reportedSize \_w h' -> h' ] @@ -734,10 +776,9 @@ Alignment alignOrigins = align slotGaps = columnGaps spacing $ map ann children gaps = sum slotGaps- (starts, runHeight) = runOffsets slotGaps [withVec2 reportedSize \_w h -> h | (reportedSize, _) <- children']- crossWidth = foldl' max 0 [withVec2 reportedSize \w _h -> w | (reportedSize, _) <- children']+ (starts, runHeight) = runOffsets slotGaps [withVec2 reportedSize \_w h -> h | (reportedSize, _, _) <- children']+ crossWidth = foldl' max 0 [withVec2 reportedSize \w _h -> w | (reportedSize, _, _) <- children'] - -- | Record index, sort by flexibility, process, restore order children' = toList . array (0, numChildren - 1) $ snd $ mapAccumL f (fromIntegral numChildren, budget) $ zip (reservedAfter minHeightOf sorted) sorted@@ -748,21 +789,20 @@ f (childrenRemaining, WithVec2 remW remH) (reserved, (ix, child)) = ( (childrenRemaining - 1.0, vec2 remW (max 0 $ remH - reportedHeight))- , ( ix- , child'- ) -- XXX: can use combineH here+ , (ix, child') ) where- WithVec2 _ reportedHeight = fst child'- child' = suspend (vec2 remW proposeHeight) child+ (WithVec2 _ reportedHeight, _, _) = child'+ child' = suspendGuided (vec2 remW proposeHeight) child proposeHeight = fairShare (minHeightOf child) reserved remH childrenRemaining ZStack{align, children} ->- ( foldl' max2 0 reporteds+ ( stackSize+ , firstJust [alignedMidline align stackSize reported midline | (reported, midline, _) <- suspendeds] , \placedStack -> let placedChildren = [ suspended $ Layout.placeSize align reported placedStack- | (reported, suspended) <- zip reporteds suspendeds+ | (reported, _, suspended) <- suspendeds ] in ZStack@@ -772,9 +812,21 @@ } ) where- (reporteds, suspendeds) = unzip $ map (suspend proposed) children+ suspendeds = map (suspendGuided proposed) children+ stackSize = foldl' max2 0 [reported | (reported, _, _) <- suspendeds] Grid{columnSpacing, rowSpacing, align, rows} -> ( vec2 runWidth runHeight+ , firstJust+ [ case guide of+ Just (above, below) ->+ Just $ rowStarts !! row + (rowHeights !! row - (above + below)) * alignY + above+ Nothing ->+ firstJust+ [ (+ rowStarts !! spot.spotRow) <$> alignedMidline align (vec2 0 $ spanHeight spot) reported midline+ | (spot, (reported, midline, _)) <- zip spotsInRow offeredInRow+ ]+ | (row, spotsInRow, offeredInRow, guide) <- zip4 [0 :: Int ..] spots offered guides+ ] , \placedGrid -> let justified =@@ -783,11 +835,24 @@ shiftRun Layout.cutLeft originX (Box.width placedGrid - runWidth) placedGrid placedRows = Box.withTRBL justified \t _r _b l ->- [ [ placeCell $ Layout.placeSize align reported (slot t l spot)- | (spot, (reported, placeCell)) <- zip spotsInRow offeredInRow+ [ [ placeCell $ cellBox guide spot reported midline (slot t l spot)+ | (spot, (reported, midline, placeCell)) <- zip spotsInRow offeredInRow ]- | (spotsInRow, offeredInRow) <- zip spots offered+ | (spotsInRow, offeredInRow, guide) <- zip3 spots offered guides ]+ cellBox guide spot reported midline slotBox =+ case guide of+ Just (above, below) | spot.spotRows == 1 ->+ Box.withTRBL (Layout.placeSize align reported slotBox) \_top right _bottom left ->+ Box.withTRBL slotBox \slotTop _right slotBottom _left ->+ withVec2 reported \_w h ->+ let+ runTop = slotTop + (slotBottom - slotTop - (above + below)) * alignY+ childTop = runTop + above - fromMaybe (h * 0.5) midline+ in+ Box.fromTRBL childTop right (childTop + h) left+ _ ->+ Layout.placeSize align reported slotBox slot t l spot = Box.fromTRBL top (left + spanWidth spot) (top + spanHeight spot) left where@@ -804,6 +869,7 @@ ) where Alignment alignOrigins = align+ WithVec2 _alignX alignY = alignOrigins WithVec2 offeredWidth offeredHeight = proposed spots = gridSpots rows spotted = zip (concat spots) (concat rows)@@ -818,16 +884,34 @@ | (spot, cell) <- spotted ] spanWidth spot = spanLength columnWidths columnGapsAt (alongColumns spot)- rowHeights =+ settledHeights = settleAxis offeredHeight rowGapsAt (axisRanges rowCount rowGapsAt [(alongRows spot, heightRange cell.ann) | (spot, cell) <- spotted]) [ (alongRows spot, heightRange cell.ann, \offer -> withVec2 (fst $ suspend (vec2 (spanWidth spot) offer) cell) \_w h -> h) | (spot, cell) <- spotted ]+ settledRows =+ [ [suspendGuided (vec2 (spanWidth spot) (spanLength settledHeights rowGapsAt (alongRows spot))) cell | (spot, cell) <- zip spotsInRow row]+ | (spotsInRow, row) <- zip spots rows+ ]+ guides =+ [ rowGuide [(reported, midline) | (spot, (reported, midline, _)) <- zip spotsInRow settledInRow, spot.spotRows == 1]+ | (spotsInRow, settledInRow) <- zip spots settledRows+ ]+ rowGuide cells+ | alignY == Alignment.Middle && any (isJust . snd) cells =+ let+ extents = [withVec2 reported \_w h -> let m = fromMaybe (h * 0.5) midline in (m, h - m) | (reported, midline) <- cells]+ in+ Just (maximum (map fst extents), maximum (map snd extents))+ | otherwise = Nothing+ rowHeights = zipWith (\settled guide -> maybe settled (\(above, below) -> max settled (above + below)) guide) settledHeights guides spanHeight spot = spanLength rowHeights rowGapsAt (alongRows spot) offered =- [ [suspend (vec2 (spanWidth spot) (spanHeight spot)) cell | (spot, cell) <- zip spotsInRow row]- | (spotsInRow, row) <- zip spots rows+ [ [ if isJust guide && spot.spotRows == 1 then settledCell else suspendGuided (vec2 (spanWidth spot) (spanHeight spot)) cell+ | (spot, cell, settledCell) <- zip3 spotsInRow row settledInRow+ ]+ | (spotsInRow, row, settledInRow, guide) <- zip4 spots rows settledRows guides ] (columnStarts, runWidth) = runOffsets columnGapsAt columnWidths (rowStarts, runHeight) = runOffsets rowGapsAt rowHeights@@ -845,9 +929,10 @@ -> View ViewSize stuff -> View ViewSize stuff -> (Box -> View Box (Placed stuff) -> View Box (Placed stuff) -> View Box (Placed stuff))- -> (Vec2, Box -> View Box (Placed stuff))+ -> (Vec2, Maybe Float, Box -> View Box (Placed stuff)) decorated proposed align primary secondary rebuild = ( reportedPrimary+ , midlinePrimary , \placed -> let placedPrimary = placePrimary placed@@ -855,9 +940,19 @@ rebuild placed placedPrimary $ placeSecondary (Layout.placeSize align reportedSecondary placedPrimary.ann) ) where- (reportedPrimary, placePrimary) = suspend proposed primary+ (reportedPrimary, midlinePrimary, placePrimary) = suspendGuided proposed primary (reportedSecondary, placeSecondary) = suspend reportedPrimary secondary +alignedMidline :: Alignment -> Vec2 -> Vec2 -> Maybe Float -> Maybe Float+alignedMidline (Alignment origins) outer inner midline =+ withVec2 origins \_originX originY ->+ withVec2 outer \_outerWidth outerHeight ->+ withVec2 inner \_innerWidth innerHeight ->+ (+ (outerHeight - innerHeight) * originY) <$> midline++firstJust :: [Maybe a] -> Maybe a+firstJust = listToMaybe . catMaybes+ -- * Internals inf :: Float@@ -992,7 +1087,7 @@ sized -> sized known (range, probed) = case range of- (Just lo, Just hi) | lo == hi -> lo+ (Just lo, Just hi) | lo == hi -> max lo probed _ -> probed settleTracks :: Float -> (track -> (Float, Float)) -> (track -> Float -> Float) -> [track] -> [Float]@@ -1158,7 +1253,7 @@ room = max 0 (budget - sum lengths) wanted = case range of- (Just lo, Just hi) | lo == hi -> lo+ (Just lo, Just hi) | lo == hi -> max lo (probe current) _ -> probe (current + room) given = fillUp (wanted - current) [(track, snd (ranges !! track) - lengths !! track) | track <- spanned] openLengths =
test/Spec.hs view
@@ -43,6 +43,7 @@ , aspects , grids , clearances+ , midlines ] examples :: TestTree@@ -293,6 +294,102 @@ [ Box.withTRBL box \t _r _b _l -> t | box <- childBoxes Box{position = vec2 50 50, size = vec2 100 100} tree ]++midlines :: TestTree+midlines = testGroup "Midlines"+ [ testCase "Padding moves the midline by its top edge" $+ midlineOf (View.padding_ (vec4 7 0 3 0) (guided 20 6)) @?= Just 13++ , testCase "Frames place the midline with their content" $ do+ midlineOf (View.frame_ (vec2 10 40) (guided 20 6)) @?= Just 16+ midlineOf (View.flexible_ (View.heightWithin 40 40 View.unbounded) Alignment.leftTop (guided 20 6)) @?= Just 6++ , testCase "A column takes the midline of its first guided child" $+ midlineOf (View.vstack 5 Alignment.leftTop [View.frame_ (vec2 10 10) plain, guided 20 6, guided 20 9]) @?= Just 21++ , testCase "Decorations keep the midline of their primary view" $+ midlineOf (View.background_ plain (View.padding_ 2 $ guided 20 6)) @?= Just 8++ , testCase "Middle-aligned rows line up midlines and grow around them" $ do+ let tree = View.hstack 0 Alignment.leftMiddle [guided 20 6, guided 10 8]+ sizeOf tree @?= vec2 20 22+ midlineOf tree @?= Just 8+ midlinesOn tree [6, 8] @?= [47, 47]++ , testCase "Rows centre children without a midline on the line" $ do+ let tree = View.hstack 0 Alignment.leftMiddle [guided 20 6, View.frame_ (vec2 10 30) plain]+ sizeOf tree @?= vec2 20 30+ midlinesOn tree [6, 15] @?= [50, 50]++ , testCase "Padding below a guided child doesn't move its text" $ do+ let+ label = guided 20 6+ button = View.padding_ (vec4 3 0 23 0) (guided 20 6)+ midlinesOn (View.hstack 0 Alignment.leftMiddle [label, button]) [6, 9] @?= [36, 36]++ , testCase "Rows hug children whose midline sits outside their box" $ do+ let+ raised = View.hstack 0 Alignment.leftMiddle [View.frame_ (vec2 10 10) (guided 40 2)]+ sunken = View.hstack 0 Alignment.leftMiddle [View.flexible_ (View.heightWithin 10 10 View.unbounded) Alignment.leftTop (guided 40 30)]+ (sizeOf raised, midlineOf raised) @?= (vec2 10 10, Just (-13))+ (sizeOf sunken, midlineOf sunken) @?= (vec2 10 10, Just 30)++ , testCase "Rows without midlines centre boxes as before" $ do+ let boxes = childBoxes squareRoot $ View.hstack 0 Alignment.leftMiddle [View.frame_ (vec2 10 10) plain, View.frame_ (vec2 10 30) plain]+ map Box.height boxes @?= [10, 30]+ map top boxes @?= [45, 35]++ , testCase "Top-aligned rows ignore midlines" $ do+ let tree = View.hstack 0 Alignment.leftTop [guided 20 6, guided 10 8]+ sizeOf tree @?= vec2 20 20+ map top (childBoxes squareRoot tree) @?= [0, 0]++ , testCase "Middle-aligned grid rows line up midlines and grow around them" $ do+ let tree = View.grid 0 0 Alignment.leftMiddle [[guided 20 6, guided 10 8]]+ sizeOf tree @?= vec2 20 22+ midlineOf tree @?= Just 8+ zipWith (+) (concatMap (map top) (cellBoxes tree)) [6, 8] @?= [47, 47]++ , testCase "Grid rows fit cells that report more than they measured" $ do+ let+ tree =+ View.grid 0 0 Alignment.leftTop+ [ [View.hstack 0 Alignment.leftMiddle [guided 20 6, guided 10 8]]+ , [View.frame_ (vec2 10 10) plain]+ ]+ sizeOf tree @?= vec2 20 32+ map (map top) (cellBoxes tree) @?= [[0], [22]]+ map (map Box.height) (cellBoxes tree) @?= [[22], [10]]++ , testCase "Grid cells spanning rows centre their boxes" $ do+ let+ tree =+ View.grid 0 0 Alignment.leftMiddle+ [ [View.span_ 1 2 (guided 24 4), guided 20 6]+ , [guided 10 8]+ ]+ map (map top) (cellBoxes tree) @?= [[38, 35], [55]]++ , testCase "Top-aligned grids ignore midlines" $ do+ let tree = View.grid 0 0 Alignment.leftTop [[guided 20 6, guided 10 8]]+ sizeOf tree @?= vec2 20 20+ map (map top) (cellBoxes tree) @?= [[0, 0]]+ ]+ where+ cellBoxes tree =+ case View.layout squareRoot tree of+ Grid{rows} -> map (map (.ann)) rows+ _ -> []+ guided :: Float -> Float -> View () (View.GuidedFun ())+ guided height midline =+ View.guidedFun (View.fixed_ (vec2 10 height)) \_proposed -> (vec2 10 height, Just midline, const ())+ plain = View.guidedFun (View.fixed_ 10) \proposed -> (proposed, Nothing, const ())+ squareRoot = Box{position = vec2 50 50, size = vec2 100 100}+ reportOf tree = View.suspendGuided squareRoot.size (View.measure tree)+ sizeOf tree = let (reported, _, _) = reportOf tree in reported+ midlineOf tree = let (_, midline, _) = reportOf tree in midline+ top box = Box.withTRBL box \t _r _b _l -> t+ midlinesOn tree midlines' = zipWith (+) (map top $ childBoxes squareRoot tree) midlines' row :: Box row = Box{position = vec2 200 50, size = vec2 400 100}