about summary refs log tree commit diff stats
path: root/src/layout
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-24 15:53:11 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-24 15:53:11 +0100
commit06696ec0a2c7486a35550bfb9a6f6caba439d0a2 (patch)
tree4c3f539e011e0ad14b452eb6ccc0a96eb8fa69ba /src/layout
parent0b40abbaa7fdfe6bd0150fd25456e7207d58ba1f (diff)
downloadchawan-06696ec0a2c7486a35550bfb9a6f6caba439d0a2.tar.gz
Fix node to cell mapping
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/box.nim7
-rw-r--r--src/layout/engine.nim24
2 files changed, 9 insertions, 22 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index 07dce0ed..d0cf99c4 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -7,7 +7,7 @@ import io/term
 type
   Viewport* = ref object
     term*: TermAttributes
-    nodes*: seq[Node]
+    node*: Node
     root*: BlockBox
     map*: seq[CSSBox]
 
@@ -18,7 +18,6 @@ type
     specified*: CSSSpecifiedValues
     node*: Node
     element*: Element
-    nodes*: seq[Node]
 
   InlineAtom* = ref object of RootObj
     relx*: int
@@ -31,7 +30,7 @@ type
     fontweight*: int
     textdecoration*: CSSTextDecoration
     color*: CSSColor
-    nodes*: seq[Node]
+    node*: Node
 
   InlineRow* = ref object
     atoms*: seq[InlineAtom]
@@ -50,7 +49,7 @@ type
     whitespace*: bool
     maxwidth*: int
     viewport*: Viewport
-    nodes*: seq[Node]
+    node*: Node
 
   BlockContext* = ref object of InlineAtom
     inline*: InlineContext
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 10cc1374..441f6233 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -26,7 +26,7 @@ func px(l: CSSLength, state: Viewport, p = 0): int {.inline.} =
 type InlineState = object
   ictx: InlineContext
   skip: bool
-  nodes: seq[Node]
+  node: Node
   word: InlineWord
   maxwidth: int
   specified: CSSSpecifiedValues
@@ -58,7 +58,7 @@ proc newWord(state: var InlineState) =
   word.fontstyle = specified{"font-style"}
   word.fontweight = specified{"font-weight"}
   word.textdecoration = specified{"text-decoration"}
-  word.nodes = state.nodes
+  word.node = state.node
   state.word = word
 
 proc finishRow(ictx: InlineContext) =
@@ -128,12 +128,12 @@ proc processWhitespace(state: var InlineState, c: char) =
     else:
       state.ictx.whitespace = true
 
-proc renderText*(ictx: InlineContext, str: string, maxwidth: int, specified: CSSSpecifiedValues, nodes: seq[Node]) =
+proc renderText*(ictx: InlineContext, str: string, maxwidth: int, specified: CSSSpecifiedValues, node: Node) =
   var state: InlineState
   state.specified = specified
   state.ictx = ictx
   state.maxwidth = maxwidth
-  state.nodes = nodes
+  state.node = node
   state.newWord()
 
   #if str.strip().len > 0:
@@ -271,16 +271,13 @@ proc alignInlineBlock(bctx: BlockContext, box: InlineBlockBox, parentcss: CSSSpe
   box.ictx.whitespace = false
 
 proc alignInline(bctx: BlockContext, box: InlineBox) =
-  if box.node != nil:
-    bctx.viewport.nodes.add(box.node)
-
   let box = InlineBox(box)
   assert box.ictx != nil
   if box.newline:
     box.ictx.flushLine()
   for text in box.text:
     assert box.children.len == 0
-    box.ictx.renderText(text, bctx.compwidth, box.specified, box.nodes)
+    box.ictx.renderText(text, bctx.compwidth, box.specified, box.node)
 
   for child in box.children:
     case child.t
@@ -294,8 +291,6 @@ proc alignInline(bctx: BlockContext, box: InlineBox) =
       bctx.alignInlineBlock(child, box.specified)
     else:
       assert false, "child.t is " & $child.t
-  if box.node != nil:
-    discard bctx.viewport.nodes.pop()
 
 proc alignInlines(bctx: BlockContext, inlines: seq[CSSBox]) =
   let ictx = bctx.newInlineContext()
@@ -341,14 +336,11 @@ proc alignBlocks(bctx: BlockContext, blocks: seq[CSSBox], blockgroup: var seq[CS
       alignBlock(child)
     of DISPLAY_INLINE:
       if child.inlinelayout:
-        child.nodes = bctx.viewport.nodes
         blockgroup.add(child)
       else:
         if child.node != nil:
-          bctx.viewport.nodes.add(child.node)
+          bctx.viewport.node = child.node
         bctx.alignBlocks(child.children, blockgroup, child.node)
-        if child.node != nil:
-          discard bctx.viewport.nodes.pop()
         #eprint "put"
     of DISPLAY_INLINE_BLOCK:
       blockgroup.add(child)
@@ -357,8 +349,6 @@ proc alignBlocks(bctx: BlockContext, blocks: seq[CSSBox], blockgroup: var seq[CS
 proc alignBlock(box: BlockBox) =
   if box.bctx.done:
     return
-  if box.node != nil:
-    box.bctx.viewport.nodes.add(box.node)
   if box.inlinelayout:
     # Box only contains inline boxes.
     box.bctx.alignInlines(box.children)
@@ -368,8 +358,6 @@ proc alignBlock(box: BlockBox) =
     let bctx = box.bctx
     flush_group()
     box.bctx.arrangeBlocks()
-  if box.node != nil:
-    discard box.bctx.viewport.nodes.pop()
   box.bctx.done = true
 
 proc getBox(specified: CSSSpecifiedValues): CSSBox =