aboutsummaryrefslogtreecommitdiffstats
path: root/src/css
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-12-07 16:54:25 +0100
committerbptato <nincsnevem662@gmail.com>2024-12-07 16:54:25 +0100
commit003e190e414c2f75e362b1880ede402665c45029 (patch)
treeb756abf0a6474c2932a0e0e5fb53616f15411ea8 /src/css
parentc59356f7fb5f58955d5153a05fb37f9eb226d971 (diff)
downloadchawan-003e190e414c2f75e362b1880ede402665c45029.tar.gz
layout: round inline block padding to cells
Seems more compatible with websites that use smaller fonts + padding for styled code tags.
Diffstat (limited to 'src/css')
-rw-r--r--src/css/layout.nim8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim
index 2e1fcd03..d0a19250 100644
--- a/src/css/layout.nim
+++ b/src/css/layout.nim
@@ -39,6 +39,7 @@ type
LayoutContext = ref object
attrsp: ptr WindowAttributes
+ cellSize: Size # size(w = attrsp.ppc, h = attrsp.ppl)
positioned: seq[PositionedItem]
myRootProperties: CSSComputedValues
# placeholder text data
@@ -1559,7 +1560,11 @@ proc addInlineAbsolute(ictx: var InlineContext; state: var InlineState;
proc addInlineBlock(ictx: var InlineContext; state: var InlineState;
box: BlockBox) =
let lctx = ictx.lctx
- let sizes = lctx.resolveFloatSizes(ictx.space, box.computed)
+ var sizes = lctx.resolveFloatSizes(ictx.space, box.computed)
+ for i, it in sizes.padding.mpairs:
+ let cs = lctx.cellSize[i]
+ it.start = (it.start div cs).toInt.toLayoutUnit * cs
+ it.send = (it.send div cs).toInt.toLayoutUnit * cs
box.state = BoxLayoutState()
let marginBottom = lctx.layoutRootBlock(box, offset(x = 0, y = 0), sizes)
# Apply the block box's properties to the atom itself.
@@ -3403,6 +3408,7 @@ proc layout*(root: StyledNode; attrsp: ptr WindowAttributes): BlockBox =
)
let lctx = LayoutContext(
attrsp: attrsp,
+ cellSize: size(w = attrsp.ppc, h = attrsp.ppl),
positioned: @[PositionedItem(), PositionedItem()],
myRootProperties: rootProperties(),
imgText: newStyledText("[img]"),