Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

Inline text in a scrolled element is scrolled once, as Chrome scrolls it, not twice (closes #46). blitz-paint's render_element drew a scroller's contents scrolled two ways: it subtracted the scroll offset from content_position, and (since #18) pre-translated the transform by it. Inline text and a text input's text are placed by both, so a box with scrollTop 60 showed its text 120 px up: "Three" over "Four" where Chrome 148 shows "Two" over "Three". Block children are drawn through the transform alone, which is why sdk/ui's overflow-scroll case (block rows) never caught it. content_position now stays put and the transform scrolls everything. #37's text mask is unchanged: Chrome masks a scroller's background with its text unscrolled (scrollTop read back 60, and a forced repaint kept the mask at "One" over "Two"), and raea's mask already ignored the scroll. Its doc comment now says so instead of calling the offset a gap.

shinyobjectz0ee51a1c64d0
diff --git a/bench/background-clip-text/check.sh b/bench/background-clip-text/check.sh
index 12b9b219..a9a3f207 100755
--- a/bench/background-clip-text/check.sh
+++ b/bench/background-clip-text/check.sh
@@ -4,6 +4,9 @@
# alone (second), and background-clip on a block holding the word in a block of its own (third). In each line the G's
# stem must be the gradient's pink, and the box beside and above the word the page's #111 (it was the gradient: the
# box was filled and the text was invisible). Chrome 148 gives these same pixels.
+# scrolled.tsx scrolls two boxes of "One Two Three Four" down a line. Only "Three" reaches past x 112, so a strip at x
+# 112-140 tells the lines apart: the plain box must show "Two" over "Three" as Chrome does (#46: raea scrolled inline
+# text twice, "Three" over "Four"), and the text-clipped one "One" over "Two", Chrome's mask being its text unscrolled.
# Exits 1 on a failure.
# bench/background-clip-text/check.sh (RAEA_BIN: the raea to run, default target/release/raea)
cd "$(dirname "$0")/../.." || exit 2
@@ -18,6 +21,13 @@ near() { # X,Y R G B: each channel within 6
(( ${got[0]} - $2 <= 6 && $2 - ${got[0]} <= 6 && ${got[1]} - $3 <= 6 && $3 - ${got[1]} <= 6 && ${got[2]} - $4 <= 6 && $4 - ${got[2]} <= 6 )) && return
echo "FAIL at $1: ${got[*]}, wanted $2 $3 $4 ($5)"; status=1
}
+ink() { # X,Y,W,H: whether the strip has text in it (its brightest pixel well above the page's #111)
+ [ "$(magick "$OUT/b.png" -crop "$3x$4+$1+$2" +repage -format '%[fx:maxima.r>0.5?1:0]' info:)" = 1 ]
+}
+strip() { # Y WANT WHAT
+ local got=empty; ink 112 "$1" 28 40 && got=ink
+ [ "$got" = "$2" ] || { echo "FAIL at x 112-140, y $1: $got, wanted $2 ($3)"; status=1; }
+}
status=0
for y in 60 180 300; do
near 8,$y 251 2 204 "the G's stem, in the gradient"
@@ -26,5 +36,10 @@ done
near 200,10 17 17 17 "above the first line's glyphs"
near 200,130 17 17 17 "above the second line's glyphs"
near 200,250 17 17 17 "above the third line's glyphs"
+"$BIN" render bench/background-clip-text/scrolled.tsx -o "$OUT/b.png" > "$OUT/log" 2>&1 || { echo "FAIL render scrolled.tsx (log below)"; sed 's/^/ /' "$OUT/log"; exit 1; }
+strip 10 empty "the plain scroller's first line: Two"
+strip 70 ink "the plain scroller's second line: Three"
+strip 130 empty "the clipped scroller's first line: One"
+strip 190 empty "the clipped scroller's second line: Two"
[ $status = 0 ] && echo "PASS background-clip: text"
exit $status
diff --git a/bench/background-clip-text/scrolled.tsx b/bench/background-clip-text/scrolled.tsx
new file mode 100644
index 00000000..b28528e5
--- /dev/null
+++ b/bench/background-clip-text/scrolled.tsx
@@ -0,0 +1,16 @@
+// bench/background-clip-text/check.sh's scrolled case: two scrollers of "One Two Three Four" (48px, a 60px line, 120px
+// tall), each scrolled down a line. The first is plain pink text: Chrome 148 shows "Two" and "Three" (#46: raea showed
+// "Three" and "Four", the text scrolled twice). The second clips a gradient to its text: Chrome masks it with the text
+// as at scrollTop 0, so it shows "One" and "Two" (#37).
+import { Composition, registerRoot } from "raea";
+const box = { height: 120, overflow: "hidden" } as const;
+const clip = { ...box, background: "linear-gradient(90deg,#f0c,#0cf)", backgroundClip: "text", color: "transparent" } as const;
+function Scrolled() {
+ return (
+ <div style={{ width: 640, height: 240, background: "#111", font: "bold 48px sans-serif", lineHeight: "60px" }}>
+ <div style={{ ...box, color: "#f0c" }} scrollTop={60}>One<br />Two<br />Three<br />Four</div>
+ <div style={clip} scrollTop={60}>One<br />Two<br />Three<br />Four</div>
+ </div>
+ );
+}
+registerRoot(() => <Composition id="scrolled" component={Scrolled} width={640} height={240} fps={30} durationInFrames={1} />);
diff --git a/vendor/blitz-paint/src/render.rs b/vendor/blitz-paint/src/render.rs
index ebc22935..21aca4ad 100644
--- a/vendor/blitz-paint/src/render.rs
+++ b/vendor/blitz-paint/src/render.rs
@@ -1263,13 +1263,9 @@ impl<'dom, 'a> BlitzDomPainter<'dom, 'a> {
None,
None,
|scene| {
- // Now that background has been drawn, offset pos and cx in order to draw our contents scrolled
- let content_position = Point {
- x: content_position.x - node.scroll_offset().x,
- y: content_position.y - node.scroll_offset().y,
- };
-
- // raea: scrolled in the element's axes (#18)
+ // raea: now that the background has been drawn, the contents scrolled, in the element's
+ // axes (#18), by the transform alone: content_position stays put, since inline text is
+ // placed by both and was scrolled twice (#46)
cx.transform = cx.transform.pre_translate(Vec2 {
x: -node.scroll_offset().x * self.scale,
y: -node.scroll_offset().y * self.scale,
@@ -1651,7 +1647,8 @@ impl ElementCx<'_, '_> {
/// raea: the element's text as a mask (background-clip: text, #37): its glyphs where they're drawn, opaque and
/// without their shadows, for the background group under them to keep only what they cover (DestIn). Its own
- /// inline layout and, as Chrome's, the text of every element inside it at its place (a scroller's offset aside).
+ /// inline layout and, as Chrome's, the text of every element inside it at its place, unscrolled: Chrome 148 masks
+ /// a scroller's background with its text as at scrollTop 0 (bench/background-clip-text/check.sh's scrolled case).
pub(super) fn draw_text_mask(&self, scene: &mut impl PaintScene) {
if let Some(text_layout) = self.element.inline_layout_data.as_ref().filter(|_| self.node.flags.is_inline_root()) {
let l = self.node.final_layout();
diff --git a/vendor/vendor.toml b/vendor/vendor.toml
index 892a4b8c..272a7cfb 100644
--- a/vendor/vendor.toml
+++ b/vendor/vendor.toml
@@ -56,7 +56,7 @@ exit = "a bevy_ui_widgets release on parley 0.12"
path = "vendor/blitz-paint"
upstream = "crates.io:0.3.0-beta.4"
kind = "patch"
-reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18); background-clip: text, its background masked by the text of the element and everything in it (#37); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's spreading box shadow (data-raea-bevy-shadow) spread as bevy_ui spreads it, its width by the spread and its height and corners by the same ratio"
+reason = "angled tile gradients, many-tile gradient layers as one brush, text-shadow, ellipsis, inline-box opacity, box-shadow blur as Chrome's; filters by GPU passes (B4a/B4b); z-index boxes clipped by the overflow between them and their stacking context; a range input's thumb; what an element paints at an offset of its own (background position and tiles, box and text shadows, scroll, inline SVG) placed in its own axes under a rotated ancestor (#18); background-clip: text, its background masked by the text of the element and everything in it (#37) as Chrome does, unscrolled; inline text in a scroller scrolled once, not twice (#46); a rounded corner where one side has no width (a left-only border on a rounded box), which drew nothing; a bevy_ui node's spreading box shadow (data-raea-bevy-shadow) spread as bevy_ui spreads it, its width by the spread and its height and corners by the same ratio"
exit = "a Blitz release that draws these"
[blitz-dom]