diff options
author | bptato <nincsnevem662@gmail.com> | 2025-03-03 22:07:20 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2025-03-03 22:42:17 +0100 |
commit | bd5ef49b64991607bde95e0c0a487b636d59ae42 (patch) | |
tree | f5a5c71fd0323db131eaffb2b63e349bd3383f97 | |
parent | a0b345318e08d73eaedfc9b1caeec5b78fc270e3 (diff) | |
download | chawan-bd5ef49b64991607bde95e0c0a487b636d59ae42.tar.gz |
layout: adjust table cell height to fill rows
Achieved by generating an anonymous flow root child for the contents and positioning that. (Not the cell contents directly - that wouldn't work because of inline child boxes.)
-rw-r--r-- | src/css/csstree.nim | 5 | ||||
-rw-r--r-- | src/css/layout.nim | 17 | ||||
-rw-r--r-- | test/layout/table.color.expected | 6 |
3 files changed, 16 insertions, 12 deletions
diff --git a/src/css/csstree.nim b/src/css/csstree.nim index 80d73758..79872920 100644 --- a/src/css/csstree.nim +++ b/src/css/csstree.nim @@ -263,6 +263,11 @@ proc getParent(frame: var TreeFrame; computed: CSSValues; display: CSSDisplay): if frame.computed{"list-style-position"} == ListStylePositionOutside and frame.children.len >= 2: return frame.children[1].anonChildren + of DisplayTableCell: + if frame.anonComputed == nil: + frame.anonComputed = frame.inheritFor(DisplayFlowRoot) + frame.children.add(initStyledAnon(frame.parent, frame.anonComputed)) + return frame.children[^1].anonChildren elif display in DisplayInternalTable: return frame.addAnonTable(parentDisplay, display) else: diff --git a/src/css/layout.nim b/src/css/layout.nim index 7d94c138..f943d55e 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -2322,15 +2322,14 @@ proc preLayoutTableRow(pctx: var TableContext; row, parent: BlockBox; return ctx proc alignTableCell(cell: BlockBox; availableHeight, baseline: LUnit) = - case cell.computed{"vertical-align"}.keyword - of VerticalAlignTop: - cell.state.offset.y = 0 - of VerticalAlignMiddle: - cell.state.offset.y = availableHeight div 2 - cell.state.size.h div 2 - of VerticalAlignBottom: - cell.state.offset.y = availableHeight - cell.state.size.h - else: - cell.state.offset.y = baseline - cell.state.firstBaseline + let firstChild = BlockBox(cell.firstChild) + if firstChild != nil: + firstChild.state.offset.y = case cell.computed{"vertical-align"}.keyword + of VerticalAlignTop: 0.toLUnit() + of VerticalAlignMiddle: availableHeight div 2 - cell.state.size.h div 2 + of VerticalAlignBottom: availableHeight - cell.state.size.h + else: baseline - cell.state.firstBaseline + cell.state.size.h = availableHeight proc layoutTableRow(tctx: TableContext; ctx: RowContext; parent, row: BlockBox) = diff --git a/test/layout/table.color.expected b/test/layout/table.color.expected index 532766bb..3864b50a 100644 --- a/test/layout/table.color.expected +++ b/test/layout/table.color.expected @@ -1,10 +1,10 @@ caption -[48;2;0;0;255m lorem ipsum dolor sit amet, consectetur [49m +[48;2;0;0;255m [48;2;255;0;0m [48;2;0;0;255m lorem ipsum dolor sit amet, consectetur [49m [48;2;0;0;255m [48;2;255;0;0mone two [48;2;0;0;255m adipiscing elit, sed do eiusmod tempor [49m [48;2;0;0;255m [48;2;255;0;0mthree [48;2;0;0;255m incididunt ut labore et dolore magna [49m [48;2;0;0;255m [48;2;255;0;0mfour five[48;2;0;0;255m c d aliqua いろはにほへとちりぬるをわかよたれ [49m [48;2;0;0;255m [48;2;255;0;0msix seven[48;2;0;0;255m そつ one two three four five six seven [49m [48;2;0;0;255m [48;2;255;0;0meight [48;2;0;0;255m eight nine ten elevenn twelve thirteen [49m -[48;2;0;0;255m fourteen sixteen seventeen eighteen [49m -[48;2;0;0;255m internationalization nineteen [49m +[48;2;0;0;255m [48;2;255;0;0m [48;2;0;0;255m fourteen sixteen seventeen eighteen [49m +[48;2;0;0;255m [48;2;255;0;0m [48;2;0;0;255m internationalization nineteen [49m aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |