aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-02 17:05:13 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-02 17:07:08 +0100
commit32391be24d45184b3bba3df6989037cab36f9269 (patch)
treea78e450fd3ff270d41ac5d71ae5f451ee3598dcf
parentbdb953704fa8ad56babf1e6935281aa7c18f5cd3 (diff)
downloadchawan-32391be24d45184b3bba3df6989037cab36f9269.tar.gz
layout: remove inline rounding
It broke styles like "margin-top: -5px; padding-top: 5px", because the margin would be taken as-is, and the padding rounded to 0. Now they cancel each other out again. (I think I had added this to reduce error caused by line-height, but we don't have line-height anymore.)
-rw-r--r--src/layout/engine.nim5
-rw-r--r--src/layout/layoutunit.nim3
-rw-r--r--test/layout/fractional-margin-cancels-fractional-padding.expected1
-rw-r--r--test/layout/fractional-margin-cancels-fractional-padding.html2
4 files changed, 5 insertions, 6 deletions
diff --git a/src/layout/engine.nim b/src/layout/engine.nim
index 9f176437..4c1fcc28 100644
--- a/src/layout/engine.nim
+++ b/src/layout/engine.nim
@@ -454,7 +454,7 @@ proc shiftAtoms(ictx: var InlineContext; marginTop: LayoutUnit) =
let offsetyShifted = shiftTop + offsety
var areaY: LayoutUnit = 0
for i, atom in ictx.lbstate.atoms:
- atom.offset.y = (atom.offset.y + offsetyShifted).round(cellHeight)
+ atom.offset.y = atom.offset.y + offsetyShifted
areaY = max(atom.offset.y, areaY)
#TODO why not offsetyShifted here?
let minHeight = atom.offset.y - offsety + atom.size.h
@@ -513,12 +513,11 @@ proc alignLine(ictx: var InlineContext) =
let ch = ictx.cellHeight.toLayoutUnit()
ictx.lbstate.size.h = ch
# Baseline is what we computed in addAtom, or cell height if that's greater.
- ictx.lbstate.baseline = max(ictx.lbstate.baseline, ch).round(ictx.cellHeight)
+ ictx.lbstate.baseline = max(ictx.lbstate.baseline, ch)
# Resize according to the baseline and atom sizes.
ictx.lbstate.size.h = ictx.lbstate.resizeLine(ictx.lctx)
# Now we can calculate the actual position of atoms inside the line.
let marginTop = ictx.lbstate.positionAtoms(ictx.lctx)
- #TODO this does not really work with rounding :/
ictx.lbstate.baseline += ictx.lbstate.paddingTop
# Finally, offset all atoms' y position by the largest top margin and the
# line box's top padding.
diff --git a/src/layout/layoutunit.nim b/src/layout/layoutunit.nim
index 7e3ddb09..1b526fb7 100644
--- a/src/layout/layoutunit.nim
+++ b/src/layout/layoutunit.nim
@@ -48,8 +48,5 @@ func `$`*(a: LayoutUnit): string =
func min*(a, b: LayoutUnit): LayoutUnit {.borrow.}
func max*(a, b: LayoutUnit): LayoutUnit {.borrow.}
-func round*(a: LayoutUnit; prec: int): LayoutUnit =
- return (a div prec).toInt * prec
-
func ceilTo*(a: LayoutUnit; prec: int): LayoutUnit =
return (1 + ((a - 1) div prec).toInt) * prec
diff --git a/test/layout/fractional-margin-cancels-fractional-padding.expected b/test/layout/fractional-margin-cancels-fractional-padding.expected
new file mode 100644
index 00000000..9daeafb9
--- /dev/null
+++ b/test/layout/fractional-margin-cancels-fractional-padding.expected
@@ -0,0 +1 @@
+test
diff --git a/test/layout/fractional-margin-cancels-fractional-padding.html b/test/layout/fractional-margin-cancels-fractional-padding.html
new file mode 100644
index 00000000..2988e412
--- /dev/null
+++ b/test/layout/fractional-margin-cancels-fractional-padding.html
@@ -0,0 +1,2 @@
+<div style="padding-top: .5em; margin-top: -.5em">
+test