diff options
author | bptato <nincsnevem662@gmail.com> | 2022-08-18 22:46:18 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-08-18 22:46:18 +0200 |
commit | 2d65840eb25675c046a6df144fd1d0d29a5a2514 (patch) | |
tree | 14f878abd62e6d3e4995b28a72ce81c09506c118 /src/layout | |
parent | 6a990cef8eac9bf11d785d942873f9a5fa614585 (diff) | |
download | chawan-2d65840eb25675c046a6df144fd1d0d29a5a2514.tar.gz |
Work on tables
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/box.nim | 7 | ||||
-rw-r--r-- | src/layout/engine.nim | 58 |
2 files changed, 59 insertions, 6 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim index 780755cd..2db2a78a 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -128,6 +128,13 @@ type ListItemBox* = ref object of BlockBox marker*: InlineContext + + TableCellBox* = ref object of BlockBox + + TableRowGroupBox* = ref object of BlockBox + + TableRowBox* = ref object of BlockBox + TableBox* = ref object of BlockBox InlineBlockBox* = ref object of InlineAtom diff --git a/src/layout/engine.nim b/src/layout/engine.nim index cabd4f96..20143119 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -385,6 +385,26 @@ proc newBlockBox(parent: BlockBox, box: BlockBoxBuilder): BlockBox = result = newBlockBox_common(parent, box) result.shrink = result.computed{"width"}.auto and parent.shrink +proc newTableCellBox(parent: BlockBox, box: TableCellBoxBuilder): TableCellBox = + new(result) + result.newBlockBox_common2(parent, box) + result.shrink = result.computed{"width"}.auto and parent.shrink + +proc newTableRowGroupBox(parent: BlockBox, box: TableRowGroupBoxBuilder): TableRowGroupBox = + new(result) + result.newBlockBox_common2(parent, box) + result.shrink = result.computed{"width"}.auto and parent.shrink + +proc newTableRowBox(parent: BlockBox, box: TableRowBoxBuilder): TableRowBox = + new(result) + result.newBlockBox_common2(parent, box) + result.shrink = result.computed{"width"}.auto and parent.shrink + +proc newTableBox(parent: BlockBox, box: TableBoxBuilder): TableBox = + new(result) + result.newBlockBox_common2(parent, box) + result.shrink = result.computed{"width"}.auto and parent.shrink + proc newListItem(parent: BlockBox, builder: ListItemBoxBuilder): ListItemBox = new(result) result.newBlockBox_common2(parent, builder.content) @@ -613,8 +633,34 @@ proc positionBlocks(bctx: BlockBox) = bctx.width += bctx.padding_left bctx.width += bctx.padding_right +proc buildTableCell(box: TableCellBoxBuilder, parent: TableRowBox): TableCellBox = + result = parent.newTableCellBox(box) + if box.inlinelayout: + result.buildInlineLayout(box.children) + else: + result.buildBlockLayout(box.children, box.node) + +proc buildTableRow(box: TableRowBoxBuilder, parent: TableBox): TableRowBox = + result = parent.newTableRowBox(box) + for child in box.children: + case child.computed{"display"} + of DISPLAY_TABLE_CELL: + result.nested.add(buildTableCell(TableCellBoxBuilder(child), result)) + else: + discard + #TODO assert false + proc buildTable(box: TableBoxBuilder, parent: BlockBox): TableBox = - discard + result = parent.newTableBox(box) + for child in box.children: + case child.computed{"display"} + of DISPLAY_TABLE_ROW: + result.nested.add(buildTableRow(TableRowBoxBuilder(child), result)) + of DISPLAY_TABLE_ROW_GROUP: + discard + else: + discard + #TODO assert false proc buildBlocks(bctx: BlockBox, blocks: seq[BoxBuilder], node: StyledNode) = for child in blocks: @@ -682,26 +728,26 @@ proc getMarkerBox(computed: CSSComputedValues, listItemCounter: int): MarkerBoxB proc getListItemBox(computed: CSSComputedValues, listItemCounter: int): ListItemBoxBuilder = new(result) - result.computed = computed.copyProperties() + result.computed = computed result.marker = getMarkerBox(computed, listItemCounter) proc getTableBox(computed: CSSComputedValues): TableBoxBuilder = new(result) - result.computed = computed.copyProperties() + result.computed = computed # Also known as <tbody>. proc getTableRowGroupBox(computed: CSSComputedValues): TableRowGroupBoxBuilder = new(result) - result.computed = computed.copyProperties() + result.computed = computed proc getTableRowBox(computed: CSSComputedValues): TableRowBoxBuilder = new(result) - result.computed = computed.copyProperties() + result.computed = computed # For <th> and <td>. proc getTableCellBox(computed: CSSComputedValues): TableCellBoxBuilder = new(result) - result.computed = computed.copyProperties() + result.computed = computed type BlockGroup = object parent: BoxBuilder |