aboutsummaryrefslogtreecommitdiffstats
path: root/src/css/box.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-03 20:50:26 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-03 20:50:26 +0100
commitfbfdb9752cd9c9b6faf45cfc162e07486078e7ce (patch)
treedd087acfddcb5add85848cc615d06a7d6eba2be9 /src/css/box.nim
parent1e9e2ecd33caa6fb9b84ddbd014f239128f8e4d5 (diff)
downloadchawan-fbfdb9752cd9c9b6faf45cfc162e07486078e7ce.tar.gz
layout: eliminate InlineAtom
* For boxes, we now use the box in InlineBox. * For images, wrap bmp in an InlineImage type that stores offset + size. * For text, wrap strings into TextRun objects (an offset + a string). (Ideally, TextRuns shouldn't copy at all, but that's a problem for another time.)
Diffstat (limited to 'src/css/box.nim')
-rw-r--r--src/css/box.nim31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/css/box.nim b/src/css/box.nim
index 6ec56c38..f8dca8a0 100644
--- a/src/css/box.nim
+++ b/src/css/box.nim
@@ -11,19 +11,17 @@ type
Size* = array[DimensionType, LUnit]
- InlineAtomType* = enum
- iatWord, iatInlineBlock, iatImage
-
- InlineAtom* = ref object
+ InlineImageState* = object
offset*: Offset
size*: Size
- case t*: InlineAtomType
- of iatWord:
- str*: string
- of iatInlineBlock:
- innerbox*: BlockBox
- of iatImage:
- bmp*: NetworkBitmap
+
+ InlineImage* = ref object
+ state*: InlineImageState
+ bmp*: NetworkBitmap
+
+ TextRun* = ref object
+ offset*: Offset
+ str*: string
BoxLayoutState* = object
# offset relative to parent
@@ -46,7 +44,7 @@ type
InlineBoxState* = object
startOffset*: Offset # offset of the first word, for position: absolute
areas*: seq[Area] # background that should be painted by box
- atoms*: seq[InlineAtom]
+ runs: seq[TextRun]
InlineBoxType* = enum
ibtParent, ibtText, ibtNewline, ibtBitmap, ibtBox
@@ -64,7 +62,7 @@ type
of ibtNewline:
discard
of ibtBitmap:
- bmp*: NetworkBitmap
+ image*: InlineImage
of ibtBox:
box*: BlockBox
@@ -112,6 +110,13 @@ type
inline*: InlineBox
children*: seq[BlockBox]
+# We store runs in state as a private field, so that we can both check
+# if the box type is correct and reset them on relayout by zeroing out
+# state.
+template runs*(ibox: InlineBox): seq[TextRun] =
+ assert ibox.t == ibtText
+ ibox.state.runs
+
func offset*(x, y: LUnit): Offset =
return [dtHorizontal: x, dtVertical: y]