From 264419bde7a73ba34095af65fd0f34ab88e7070a Mon Sep 17 00:00:00 2001 From: bptato Date: Wed, 8 May 2024 22:26:23 +0200 Subject: 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. --- src/layout/engine.nim | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') 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: -- cgit 1.4.1-2-gfad0