aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/css/values.nim4
-rw-r--r--src/display/pager.nim1
-rw-r--r--src/layout/box.nim3
-rw-r--r--src/layout/engine.nim71
4 files changed, 43 insertions, 36 deletions
diff --git a/src/css/values.nim b/src/css/values.nim
index fcd8e068..f323ba8b 100644
--- a/src/css/values.nim
+++ b/src/css/values.nim
@@ -75,7 +75,7 @@ type
CSSTextAlign* = enum
TEXT_ALIGN_START, TEXT_ALIGN_END, TEXT_ALIGN_LEFT, TEXT_ALIGN_RIGHT,
- TEXT_ALIGN_CENTER, TEXT_ALIGN_JUSTIFY, TEXT_ALIGN_MOZ_CENTER
+ TEXT_ALIGN_CENTER, TEXT_ALIGN_JUSTIFY, TEXT_ALIGN_CHA_CENTER
CSSListStylePosition* = enum
LIST_STYLE_POSITION_OUTSIDE, LIST_STYLE_POSITION_INSIDE
@@ -585,7 +585,7 @@ func cssTextAlign(d: CSSDeclaration): CSSTextAlign =
of "right": TEXT_ALIGN_RIGHT
of "center": TEXT_ALIGN_CENTER
of "justify": TEXT_ALIGN_JUSTIFY
- of "-moz-center": TEXT_ALIGN_MOZ_CENTER
+ of "-cha-center": TEXT_ALIGN_CHA_CENTER
else: raise newException(CSSValueError, "Invalid text align")
raise newException(CSSValueError, "Invalid text align")
diff --git a/src/display/pager.nim b/src/display/pager.nim
index 38eed767..1b98b0e2 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -109,6 +109,7 @@ proc searchPrev(pager: Pager) {.jsfunc.} =
proc statusMode(pager: Pager) =
print(HVP(pager.attrs.height + 1, 1))
+ print(SGR())
print(EL())
proc setLineEdit(pager: Pager, edit: LineEdit, mode: LineMode) =
diff --git a/src/layout/box.nim b/src/layout/box.nim
index 61e64ee0..204abc00 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -129,15 +129,14 @@ type
ListItemBox* = ref object of BlockBox
marker*: InlineContext
-
TableCellBox* = ref object of BlockBox
+ colspan*: int
TableRowGroupBox* = ref object of BlockBox
TableRowBox* = ref object of BlockBox
TableBox* = ref object of BlockBox
- columns*: seq[int] # offset of each column
InlineBlockBox* = ref object of InlineAtom
bctx*: BlockBox
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index faf1b44c..7b651e4f 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -388,7 +388,7 @@ proc newBlockBox(parent: BlockBox, box: BlockBoxBuilder): BlockBox =
proc newTableCellBox(parent: BlockBox, box: TableCellBoxBuilder): TableCellBox =
new(result)
result.newBlockBox_common2(parent, box)
- result.shrink = result.computed{"width"}.auto and parent.shrink
+ result.shrink = result.computed{"width"}.auto
proc newTableRowGroupBox(parent: BlockBox, box: TableRowGroupBoxBuilder): TableRowGroupBox =
new(result)
@@ -410,10 +410,6 @@ proc newListItem(parent: BlockBox, builder: ListItemBoxBuilder): ListItemBox =
result.newBlockBox_common2(parent, builder.content)
result.shrink = result.computed{"width"}.auto and parent.shrink
-proc newTable(parent: BlockBox, builder: TableBoxBuilder): TableBox =
- new(result)
- result.newBlockBox_common2(parent, builder)
-
proc newBlockBox(viewport: Viewport, box: BlockBoxBuilder): BlockBox =
result = newFlowRootBox(viewport, box, viewport.term.width_px)
@@ -591,13 +587,13 @@ proc positionBlocks(bctx: BlockBox) =
bctx.height += bctx.padding_top
x += bctx.padding_left
- if bctx.computed{"text-align"} == TEXT_ALIGN_MOZ_CENTER:
+ if bctx.computed{"text-align"} == TEXT_ALIGN_CHA_CENTER:
x += bctx.compwidth div 2
template apply_child(child: BlockBox) =
child.offset.y = y
child.offset.x = x + child.margin_left
- if bctx.computed{"text-align"} == TEXT_ALIGN_MOZ_CENTER:
+ if bctx.computed{"text-align"} == TEXT_ALIGN_CHA_CENTER:
child.offset.x -= child.width div 2
y += child.height
bctx.height += child.height
@@ -638,14 +634,16 @@ proc positionBlocks(bctx: BlockBox) =
proc buildTableCell(box: TableCellBoxBuilder, parent: TableRowBox): TableCellBox =
result = parent.newTableCellBox(box)
+ result.colspan = box.colspan
if box.inlinelayout:
result.buildInlineLayout(box.children)
else:
result.buildBlockLayout(box.children, box.node)
- result.offset.x += parent.width
-proc buildTableRow(box: TableRowBoxBuilder, parent: TableBox): TableRowBox =
+proc buildTableRow(box: TableRowBoxBuilder, parent: TableBox, colwidths: var seq[int]): TableRowBox =
result = parent.newTableRowBox(box)
+ if colwidths.len < box.children.len:
+ colwidths.setLen(box.children.len)
var n = 0
for child in box.children:
case child.computed{"display"}
@@ -654,38 +652,47 @@ proc buildTableRow(box: TableRowBoxBuilder, parent: TableBox): TableRowBox =
let cell = buildTableCell(cellbuilder, result)
result.nested.add(cell)
result.height = max(result.height, cell.height)
- if parent.columns.len <= n:
- parent.columns.setLen(n + 1)
- parent.columns[n] = max(cell.width, parent.columns[n])
- var i = n
+ if colwidths.len <= n:
+ colwidths.setLen(n + 1)
+ for i in n ..< n + cellbuilder.colspan:
+ colwidths[i] = max(cell.width div cellbuilder.colspan, colwidths[i])
n += cellbuilder.colspan
- if parent.columns.len <= n:
- parent.columns.setLen(n + 1)
- while i < n:
- result.width += parent.columns[i]
- inc i
+ result.width += cell.width
else:
assert false
result.offset.y += parent.height
-proc buildTable(box: TableBoxBuilder, parent: BlockBox): TableBox =
- result = parent.newTableBox(box)
- for child in box.children:
+iterator rows(builder: TableBoxBuilder): TableRowBoxBuilder =
+ for child in builder.children:
+ assert child.computed{"display"} in {DISPLAY_TABLE_ROW, DISPLAY_TABLE_ROW_GROUP}
case child.computed{"display"}
of DISPLAY_TABLE_ROW:
- let row = buildTableRow(TableRowBoxBuilder(child), result)
- result.nested.add(row)
- result.height += row.height
- result.width = max(row.width, result.width)
+ yield TableRowBoxBuilder(child)
of DISPLAY_TABLE_ROW_GROUP:
for child in TableRowGroupBoxBuilder(child).children:
- let row = buildTableRow(TableRowBoxBuilder(child), result)
- result.nested.add(row)
- result.height += row.height
- result.width = max(row.width, result.width)
- else:
- discard
- #TODO assert false
+ assert child.computed{"display"} == DISPLAY_TABLE_ROW
+ yield TableRowBoxBuilder(child)
+ else: discard
+
+proc buildTable(box: TableBoxBuilder, parent: BlockBox): TableBox =
+ result = parent.newTableBox(box)
+ var colwidths: seq[int]
+ for row in box.rows:
+ let row = buildTableRow(row, result, colwidths)
+ result.nested.add(row)
+ result.height += row.height
+ result.width = max(row.width, result.width)
+ for row in result.nested:
+ let row = TableRowBox(row)
+ row.width = result.width
+ var n = 0
+ var x = 0
+ for cell in row.nested:
+ let cell = TableCellBox(cell)
+ cell.offset.x += x
+ for i in n ..< n + cell.colspan:
+ x += colwidths[i]
+ n += cell.colspan
proc buildBlocks(bctx: BlockBox, blocks: seq[BoxBuilder], node: StyledNode) =
for child in blocks: