diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-04-09 16:27:20 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-04-09 16:27:20 +0200 |
| commit | 30792bebc5d8e555a7cb042d002035c2df3beb89 (patch) | |
| tree | effcc2931213094f3bc73eddf7b01eea2b283c85 /src | |
| parent | 90fa1cc468f4821a10941419b0dbc6916ff196f9 (diff) | |
| download | chawan-30792bebc5d8e555a7cb042d002035c2df3beb89.tar.gz | |
layout: slightly hacky flex-basis implementation
it's better than nothing. I suppose.
(Two-value flex syntax is encouraged even by the standard, so it gets
used a lot, and that sets 0, not flex-basis: auto, so not having
flex-basis breaks too many things.)
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout/engine.nim | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 8084efc9..d2d21cc0 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -2283,9 +2283,28 @@ proc layoutFlex(bctx: var BlockContext; box: BlockBox; builder: BlockBoxBuilder; let percHeight = sizes.space.h.toPercSize() while i < children.len: let builder = children[i] - let childSizes = lctx.resolveFloatSizes(sizes.space, percHeight, + var childSizes = lctx.resolveFloatSizes(sizes.space, percHeight, builder.computed) - let child = lctx.layoutFlexChild(builder, childSizes) + let flexBasis = builder.computed{"flex-basis"} + if not flexBasis.auto: + if flexDir in FlexRow: + childSizes.space.w = stretch(flexBasis.px(lctx, sizes.space.w)) + else: + childSizes.space.h = stretch(flexBasis.px(lctx, sizes.space.h)) + var child = lctx.layoutFlexChild(builder, childSizes) + if not flexBasis.auto and childSizes.space.w.isDefinite and + child.xminwidth > childSizes.space.w.u: + # first pass gave us a box that is smaller than the minimum acceptable + # width whatever reason; this may have happened because the initial flex + # basis was e.g. 0. Try to resize it to something more usable. + # Note: this is a hack; we need it because we cheat with size resolution + # by using the algorithm that was in fact designed for floats, and without + # this hack layouts with a flex-base of 0 break down horribly. + # (And we need flex-base because using auto wherever the two-value `flex' + # shorthand is used breaks down even more horribly.) + #TODO implement the standard size resolution properly + childSizes.space.w = stretch(child.xminwidth) + child = lctx.layoutFlexChild(builder, childSizes) if flexDir in FlexRow: if canWrap and (sizes.space.w.t == MIN_CONTENT or sizes.space.w.isDefinite and |