diff options
| author | bptato <nincsnevem662@gmail.com> | 2024-05-08 22:26:23 +0200 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2024-05-08 22:28:19 +0200 |
| commit | 264419bde7a73ba34095af65fd0f34ab88e7070a (patch) | |
| tree | b61ba8d412d826bc58ebfeabc63ec1017157ebb4 | |
| parent | c90c11ea3840c9d25edb16aa5e6a2c366406cb89 (diff) | |
| download | chawan-264419bde7a73ba34095af65fd0f34ab88e7070a.tar.gz | |
layout: another table colwidth fix
Turns out we also have to *expand* column width, if the specified column
width is too small *and* no unspecified column exists to take the rest
of the place.
| -rw-r--r-- | src/layout/engine.nim | 10 | ||||
| -rw-r--r-- | test/layout/table-colwidth-overconstrained-too-small.color.expected | 2 | ||||
| -rw-r--r-- | test/layout/table-colwidth-overconstrained-too-small.html | 6 |
3 files changed, 16 insertions, 2 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index 4fe4d5ce..28235c82 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -1951,7 +1951,7 @@ proc calcUnspecifiedColIndices(ctx: var TableContext; W: var LayoutUnit; weight += w inc j else: - if specifiedRatio < 1: + if specifiedRatio != 1: col.width *= specifiedRatio col.reflow = true W -= col.width @@ -1976,14 +1976,20 @@ proc redistributeWidth(ctx: var TableContext) = W -= ctx.cols.len * ctx.inlineSpacing * 2 var weight = 0f64 var totalSpecified: LayoutUnit = 0 + var hasUnspecified = false for col in ctx.cols: if col.wspecified: totalSpecified += col.width else: + hasUnspecified = true # Hack: reserve the minimum space needed for unspecified columns, # like other browsers do. totalSpecified += col.minwidth - let specifiedRatio = if totalSpecified != 0: W / totalSpecified else: 1 + var specifiedRatio = if totalSpecified != 0: W / totalSpecified else: 1 + if specifiedRatio > 1 and hasUnspecified: + # Only grow specified columns if no unspecified column exists to take the + # rest of the space. + specifiedRatio = 1 var avail = ctx.calcUnspecifiedColIndices(W, weight, specifiedRatio) var redo = true while redo and avail.len > 0 and weight != 0: diff --git a/test/layout/table-colwidth-overconstrained-too-small.color.expected b/test/layout/table-colwidth-overconstrained-too-small.color.expected new file mode 100644 index 00000000..483d97aa --- /dev/null +++ b/test/layout/table-colwidth-overconstrained-too-small.color.expected @@ -0,0 +1,2 @@ + [48;2;255;0;0me [49m [48;2;0;128;0mh? [49m + diff --git a/test/layout/table-colwidth-overconstrained-too-small.html b/test/layout/table-colwidth-overconstrained-too-small.html new file mode 100644 index 00000000..5d2bbb5b --- /dev/null +++ b/test/layout/table-colwidth-overconstrained-too-small.html @@ -0,0 +1,6 @@ +<table width=100%> +<tr> +<td width=25% bgcolor=red>e +<td width=25% bgcolor=green>h? +</tr> +</table> |