about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-12-21 21:39:30 +0100
committerbptato <nincsnevem662@gmail.com>2021-12-21 21:39:30 +0100
commit0440397664d7561e2dd6e21afc1c1128e3dd45b5 (patch)
tree92cc94c03775576719c686f58290d8a73c669e15
parent72979b36ddca08fd985ff7e263cb726f61adf498 (diff)
downloadchawan-0440397664d7561e2dd6e21afc1c1128e3dd45b5.tar.gz
Prepare for layout engine rewrite
-rw-r--r--src/layout/box.nim41
-rw-r--r--src/layout/engine.nim18
2 files changed, 46 insertions, 13 deletions
diff --git a/src/layout/box.nim b/src/layout/box.nim
index 711e5aff..556ad88d 100644
--- a/src/layout/box.nim
+++ b/src/layout/box.nim
@@ -6,12 +6,12 @@ import io/term
 
 type
   BoxType* = enum
-    INLINE, BLOCK, INLINE_BLOCK
+    BOX_INLINE, BOX_BLOCK, BOX_INLINE_BLOCK
 
-  CSSRect* = object
+  Rectangle* = object
     x1*: int
-    y1*: int
     x2*: int
+    y1*: int
     y2*: int
 
   CSSBox* = ref object of RootObj
@@ -25,6 +25,18 @@ type
     cssvalues*: CSSSpecifiedValues
     node*: Node
 
+  CSSInlineAtom* = ref object of CSSBox
+    dimensions*: Rectangle
+
+  CSSInlineRowPart* = ref object of CSSInlineAtom
+    str*: string
+    rwidth*: int
+
+  CSSInlineRow* = ref object
+    content*: seq[CSSInlineAtom]
+    rely*: int
+    width*: int
+
   InlineContext* = ref object
     fromx*: int
     fromy*: int
@@ -34,16 +46,31 @@ type
     rows*: seq[CSSRowBox]
     thisrow*: seq[CSSRowBox]
 
+    dimensions*: Rectangle
+    content*: seq[CSSInlineRow]
+    rcontent*: CSSInlineRow
+    color*: CSSColor
+    fontstyle*: CSSFontStyle
+    fontweight*: int
+    textdecoration*: CSSTextDecoration
+    nodes*: seq[Node]
+
+    maxwidth*: int
+
   BlockContext* = ref object
     fromy*: int
+    dimensions*: Rectangle
     margin_done*: int
     margin_todo*: int
     width*: int
     height*: Option[int]
+    content*: seq[CSSBox]
 
   LayoutState* = object
     nodes*: seq[Node]
     term*: TermAttributes
+    fromy*: int
+    fromx*: int
 
   CSSRowBox* = object
     x*: int
@@ -60,4 +87,10 @@ type
 
   CSSInlineBox* = ref object of CSSBox
   CSSBlockBox* = ref object of CSSBox
-  CSSInlineBlockBox* = ref object of CSSBox
+  CSSInlineBlockBox* = ref object of CSSBlockBox
+
+func width*(rectangle: Rectangle): int =
+  return rectangle.x2 - rectangle.x1
+
+func height*(rectangle: Rectangle): int =
+  return rectangle.y2 - rectangle.y1
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 26b6ce02..42067ace 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -102,7 +102,7 @@ proc applyBlockStart(state: LayoutState, box, parent: CSSBox, vals: CSSSpecified
 
 func newBlockBox(state: var LayoutState, parent: CSSBox, vals: CSSSpecifiedValues): CSSBlockBox =
   new(result)
-  result.t = BLOCK
+  result.t = BOX_BLOCK
   if parent.icontext.conty:
     parent.flushConty()
   result.x = parent.x
@@ -114,7 +114,7 @@ func newBlockBox(state: var LayoutState, parent: CSSBox, vals: CSSSpecifiedValue
 
 func newInlineBlockBox*(state: LayoutState, parent: CSSBox, vals: CSSSpecifiedValues): CSSInlineBlockBox =
   new(result)
-  result.t = INLINE_BLOCK
+  result.t = BOX_INLINE_BLOCK
   result.x = parent.icontext.fromx
 
   state.applyBlockStart(result, parent, vals)
@@ -124,7 +124,7 @@ func newInlineBlockBox*(state: LayoutState, parent: CSSBox, vals: CSSSpecifiedVa
 
 func newInlineBox*(state: LayoutState, parent: CSSBox, vals: CSSSpecifiedValues): CSSInlineBox =
   new(result)
-  result.t = INLINE
+  result.t = BOX_INLINE
   result.x = parent.x
   result.y = parent.icontext.fromy
 
@@ -145,7 +145,7 @@ type InlineState = object
   cssvalues: CSSSpecifiedValues
   x: int
 
-func maxwidth(state: InlineState): int = state.bcontext.width - state.x
+func maxwidth(state: InlineState): int = state.bcontext.width
 
 proc newRowBox(state: var InlineState) =
   state.rowbox = CSSRowBox()
@@ -208,7 +208,7 @@ proc checkWrap(state: var InlineState, r: Rune) =
         state.icontext.fromx + state.rowbox.width + state.ww + r.width() > state.maxwidth:
       state.wrapNormal(r)
   of WORD_BREAK_BREAK_ALL:
-    if state.icontext.fromx + state.rowbox.width + state.ww + r.width() > state.x + state.bcontext.width:
+    if state.icontext.fromx + state.rowbox.width + state.ww + r.width() > state.maxwidth:
       var pl: seq[Rune]
       var i = 0
       var w = 0
@@ -229,7 +229,7 @@ proc checkWrap(state: var InlineState, r: Rune) =
       state.inlineWrap()
   of WORD_BREAK_KEEP_ALL:
     if state.icontext.fromx + state.rowbox.width > state.x and
-        state.icontext.fromx + state.rowbox.width + state.ww + r.width() > state.x + state.bcontext.width:
+        state.icontext.fromx + state.rowbox.width + state.ww + r.width() > state.maxwidth:
       state.wrapNormal(r)
 
 proc preWrap(state: var InlineState) =
@@ -374,9 +374,9 @@ proc add(state: var LayoutState, parent: CSSBox, box: CSSInlineBlockBox) =
 
 proc add(state: var LayoutState, parent: CSSBox, box: CSSBox) =
   case box.t
-  of BLOCK: state.add(parent, CSSBlockBox(box))
-  of INLINE: state.add(parent, CSSInlineBox(box))
-  of INLINE_BLOCK: state.add(parent, CSSInlineBlockBox(box))
+  of BOX_BLOCK: state.add(parent, CSSBlockBox(box))
+  of BOX_INLINE: state.add(parent, CSSInlineBox(box))
+  of BOX_INLINE_BLOCK: state.add(parent, CSSInlineBlockBox(box))
 
 proc processComputedValueBox(state: var LayoutState, parent: CSSBox, values: CSSSpecifiedValues): CSSBox =
   case values{"display"}