diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-02-04 22:25:45 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-02-04 22:25:45 +0100 |
| commit | b0afdb827276f7d8516bf37659172bf8b28cda19 (patch) | |
| tree | 8eb1a52e0cacf354d76e9a126963cab3956d8d22 /src | |
| parent | 8af354f43a79953b9207e63e81ff8eb2713b34db (diff) | |
| download | chawan-b0afdb827276f7d8516bf37659172bf8b28cda19.tar.gz | |
layout: round out small list-item margins and padding
They can be especially distracting when the rounding error fluctuates
between items.
Diffstat (limited to 'src')
| -rw-r--r-- | src/css/layout.nim | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/css/layout.nim b/src/css/layout.nim index c1c264e6..a578d442 100644 --- a/src/css/layout.nim +++ b/src/css/layout.nim @@ -1053,6 +1053,17 @@ proc resolvePadding(lctx: LayoutContext; availableWidth: SizeConstraint; ) ] +proc roundSmallMarginsAndPadding(lctx: LayoutContext; + sizes: var ResolvedSizes) = + for i, it in sizes.padding.mpairs: + let cs = lctx.cellSize[i] + it.start = (it.start div cs).toInt.toLUnit * cs + it.send = (it.send div cs).toInt.toLUnit * cs + for i, it in sizes.margin.mpairs: + let cs = lctx.cellSize[i] + it.start = (it.start div cs).toInt.toLUnit * cs + it.send = (it.send div cs).toInt.toLUnit * cs + func resolvePositioned(lctx: LayoutContext; size: Size; computed: CSSValues): RelativeRect = # As per standard, vertical percentages refer to the *height*, not the width @@ -1308,6 +1319,10 @@ proc resolveBlockSizes(lctx: LayoutContext; space: AvailableSpace; #TODO parent height should be lctx height in quirks mode for percentage # resolution. sizes.resolveBlockHeight(space.h, paddingSum[dtVertical], computed, lctx) + if computed{"display"} == DisplayListItem: + # Eliminate distracting margins and padding here, because + # resolveBlockWidth may change them beforehand. + lctx.roundSmallMarginsAndPadding(sizes) return sizes proc append(a: var Strut; b: LUnit) = @@ -1704,14 +1719,7 @@ proc addInlineBlock(fstate: var FlowState; istate: var InlineState; box: BlockBox) = let lctx = fstate.lctx var sizes = lctx.resolveFloatSizes(fstate.space, box.computed) - for i, it in sizes.padding.mpairs: - let cs = lctx.cellSize[i] - it.start = (it.start div cs).toInt.toLUnit * cs - it.send = (it.send div cs).toInt.toLUnit * cs - for i, it in sizes.margin.mpairs: - let cs = lctx.cellSize[i] - it.start = (it.start div cs).toInt.toLUnit * cs - it.send = (it.send div cs).toInt.toLUnit * cs + lctx.roundSmallMarginsAndPadding(sizes) lctx.layoutRootBlock(box, sizes.margin.topLeft, sizes) # Apply the block box's properties to the atom itself. let iastate = InlineAtomState( |