aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-04-09 16:27:20 +0200
committerbptato <nincsnevem662@gmail.com>2024-04-09 16:27:20 +0200
commit30792bebc5d8e555a7cb042d002035c2df3beb89 (patch)
treeeffcc2931213094f3bc73eddf7b01eea2b283c85
parent90fa1cc468f4821a10941419b0dbc6916ff196f9 (diff)
downloadchawan-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.)
-rw-r--r--src/layout/engine.nim23
-rw-r--r--todo4
2 files changed, 23 insertions, 4 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
diff --git a/todo b/todo
index a7ef748a..e5b8a860 100644
--- a/todo
+++ b/todo
@@ -70,8 +70,8 @@ layout engine:
* reminder: this does *not* apply to flexbox; in fact it has the inverse
problem AFAICT.
- table layout: include caption in width calculation
-- flexbox: flex-basis, align-self, align-items, justify-content, proper margin
- handling
+- flexbox: align-self, align-items, justify-content, proper margin handling,
+ proper flex base size resolution
- details element
- overflow
- incremental layout & layout caching