aboutsummaryrefslogtreecommitdiffstats
path: root/src/css/box.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2025-02-08 20:17:35 +0100
committerbptato <nincsnevem662@gmail.com>2025-02-08 20:17:35 +0100
commit2c136265658450ea91cb81ee6b3a85198a0c4844 (patch)
tree71331c1fa14e71542391dc0a6501f329e5a6d39e /src/css/box.nim
parent971e49f1eb26fd6a0c980c64f199b7356f489340 (diff)
downloadchawan-2c136265658450ea91cb81ee6b3a85198a0c4844.tar.gz
box: abstract over tree traversal
Diffstat (limited to 'src/css/box.nim')
-rw-r--r--src/css/box.nim16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/css/box.nim b/src/css/box.nim
index 7bcf0f3b..dca3ade2 100644
--- a/src/css/box.nim
+++ b/src/css/box.nim
@@ -108,6 +108,22 @@ type
of ibtBox:
box*: BlockBox
+iterator children*(box: CSSBox): lent CSSBox {.inline.} =
+ if box of BlockBox:
+ let box = BlockBox(box)
+ for child in box.children:
+ yield child
+ else:
+ let ibox = InlineBox(box)
+ case ibox.t
+ of ibtParent:
+ for child in ibox.children:
+ yield child
+ of ibtBox:
+ yield CSSBox(ibox.box)
+ else:
+ discard
+
# 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.