From 2fa73721c6ddaa3a497d58f83e987e75194f300c Mon Sep 17 00:00:00 2001 From: bptato Date: Thu, 31 Oct 2024 18:00:28 +0100 Subject: layout: refactor flow and fix some bugs in the process * factor out `margin' field from box state * get rid of RootInlineFragment * `nested' -> `children' * get rid of repositionChildren pass; now we handle relative positioning and -cha-center/-cha-right separately * cha-center, cha-right no longer applies to floats * use consistent naming scheme for tests * fix float bottom margin strut not being flushed * fix inline floats changing non-fit-content width --- src/layout/box.nim | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) (limited to 'src/layout/box.nim') diff --git a/src/layout/box.nim b/src/layout/box.nim index 26b0687b..af61b88a 100644 --- a/src/layout/box.nim +++ b/src/layout/box.nim @@ -27,24 +27,20 @@ type of iatImage: bmp*: NetworkBitmap - RootInlineFragmentState* = object + BoxLayoutState* = object # offset relative to parent offset*: Offset # padding size size*: Size # overflow relative to offset overflow*: Overflow - # minimum content width + # minimum content width (usually shortest word) xminwidth*: LayoutUnit - # baseline of the first line box + # baseline of the first line box of all descendants firstBaseline*: LayoutUnit - # baseline of the last line box + # baseline of the last line box of all descendants baseline*: LayoutUnit - RootInlineFragment* = ref object - fragment*: InlineFragment # root fragment - state*: RootInlineFragmentState - SplitType* = enum stSplitStart, stSplitEnd @@ -83,27 +79,12 @@ type RelativeRect* = array[DimensionType, Span] - BlockBoxLayoutState* = object - # offset relative to parent - offset*: Offset - # padding size - size*: Size - margin*: RelativeRect #TODO get rid of this? - # overflow relative to offset - overflow*: Overflow - # minimum content width (usually shortest word) - xminwidth*: LayoutUnit - # baseline of the first line box of all descendants - firstBaseline*: LayoutUnit - # baseline of the last line box of all descendants - baseline*: LayoutUnit - BlockBox* = ref object - state*: BlockBoxLayoutState + state*: BoxLayoutState computed*: CSSComputedValues node*: StyledNode - inline*: RootInlineFragment - nested*: seq[BlockBox] + inline*: InlineFragment + children*: seq[BlockBox] func offset*(x, y: LayoutUnit): Offset = return [dtHorizontal: x, dtVertical: y] -- cgit