diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-25 17:58:43 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-25 17:58:43 +0100 |
commit | a95a40d2a2bc7e2a7030301737041e8804885ed1 (patch) | |
tree | 1a1ff776e49900ded147aee1c4e5656d3a4ac435 /src/layout | |
parent | 2b940385bf4765450f3666850b5f56930a5c4bf9 (diff) | |
download | chawan-a95a40d2a2bc7e2a7030301737041e8804885ed1.tar.gz |
layout/engine: store vertical-align at atom creation
Diffstat (limited to 'src/layout')
-rw-r--r-- | src/layout/engine.nim | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim index aa0567bb..8ae0a59c 100644 --- a/src/layout/engine.nim +++ b/src/layout/engine.nim @@ -67,6 +67,7 @@ proc newWord(state: var InlineState) = format.textdecoration = computed{"text-decoration"} format.node = state.node word.format = format + word.vertalign = computed{"vertical-align"} state.ictx.format = format state.word = word @@ -225,11 +226,10 @@ func minwidth(atom: InlineAtom): int = return cast[InlineBlockBox](atom).innerbox.xminwidth return atom.width -# pcomputed: computed values of parent, for white-space: pre, line-height -# computed: computed values of child, for vertical-align -# (TODO: surely there's a better way to do this? like storing pcomputed in ictx -# or something...) -proc addAtom(ictx: InlineContext, atom: InlineAtom, maxwidth: int, pcomputed, computed: CSSComputedValues) = +# pcomputed: computed values of parent, for white-space: pre, line-height. +# This isn't necessary the computed of ictx (e.g. they may differ for nested +# inline boxes.) +proc addAtom(ictx: InlineContext, atom: InlineAtom, maxwidth: int, pcomputed: CSSComputedValues) = var shift = ictx.computeShift(pcomputed) ictx.whitespacenum = 0 # Line wrapping @@ -240,8 +240,6 @@ proc addAtom(ictx: InlineContext, atom: InlineAtom, maxwidth: int, pcomputed, co shift = ictx.computeShift(pcomputed) if atom.width > 0 and atom.height > 0: - atom.vertalign = computed{"vertical-align"} - if shift > 0: ictx.currentLine.addSpacing(shift, ictx.cellheight, ictx.format) @@ -261,7 +259,7 @@ proc addWord(state: var InlineState) = word.str.mnormalize() #TODO this may break on EOL. word.height = state.ictx.cellheight word.baseline = word.height - state.ictx.addAtom(word, state.maxwidth, state.computed, state.computed) + state.ictx.addAtom(word, state.maxwidth, state.computed) state.newWord() # Start a new line, even if the previous one is empty @@ -465,6 +463,7 @@ proc newListItem(parent: BlockBox, builder: ListItemBoxBuilder): ListItemBox = proc newInlineBlock(viewport: Viewport, builder: BoxBuilder, parentWidth: int, parentHeight = none(int)): InlineBlockBox = new(result) result.innerbox = newFlowRootBox(viewport, builder, parentWidth, parentHeight) + result.vertalign = builder.computed{"vertical-align"} proc newInlineContext(parent: BlockBox): InlineContext = new(result) @@ -597,7 +596,7 @@ proc buildInline(viewport: Viewport, box: InlineBoxBuilder, parentWidth: int, pa of DISPLAY_INLINE_BLOCK, DISPLAY_INLINE_TABLE: let child = BlockBoxBuilder(child) let iblock = child.buildInlineBlock(box.ictx, parentWidth, parentHeight) - box.ictx.addAtom(iblock, parentWidth, box.computed, child.computed) + box.ictx.addAtom(iblock, parentWidth, box.computed) box.ictx.whitespacenum = 0 else: assert false, "child.t is " & $child.computed{"display"} @@ -622,7 +621,7 @@ proc buildInlines(parent: BlockBox, inlines: seq[BoxBuilder]): InlineContext = of DISPLAY_INLINE_BLOCK, DISPLAY_INLINE_TABLE: let child = BlockBoxBuilder(child) let iblock = child.buildInlineBlock(ictx, parent.contentWidth) - ictx.addAtom(iblock, parent.contentWidth, parent.computed, child.computed) + ictx.addAtom(iblock, parent.contentWidth, parent.computed) ictx.whitespacenum = 0 else: assert false, "child.t is " & $child.computed{"display"} |