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.

FC0a: ui/scroll_and_overflow/overflow_transform passes (SSIM 0.9954): UiTransform (Val2 translation, Rot2 rotation clockwise, scale, about the node's centre after layout) as CSS's transform; BoxShadow as CSS's box-shadow, its blur Bevy's Gaussian deviation so CSS's is twice it (a spread or a percent is refused until Bevy's width-ratio spread is drawn); and bevy_color's Luminance darker and lighter on Srgba and LinearRgba. Each checked by conformance and a mutant; in the port, no shadow, reversed turns and no scale fail, and a pixel probe of the shadow's strip is closest at Bevy's offset and blur

shinyobjectz7ca949df8719
diff --git a/bench/bevy-parity/examples.list b/bench/bevy-parity/examples.list
index aee6c9e7..b2bfce94 100644
--- a/bench/bevy-parity/examples.list
+++ b/bench/bevy-parity/examples.list
@@ -79,3 +79,4 @@ ui/layout/grid
ui/ui_scaling
ui/layout/anchor_layout
ui/layout/size_constraints
+ui/scroll_and_overflow/overflow_transform
diff --git a/bench/bevy-parity/runs.tsv b/bench/bevy-parity/runs.tsv
index 78cf4950..1e795b4d 100644
--- a/bench/bevy-parity/runs.tsv
+++ b/bench/bevy-parity/runs.tsv
@@ -78,3 +78,4 @@ ui/layout/grid - 10
ui/ui_scaling - 10
ui/layout/anchor_layout - 10
ui/layout/size_constraints - 10
+ui/scroll_and_overflow/overflow_transform - 10
diff --git a/docs/bevy-parity.md b/docs/bevy-parity.md
index c3df4671..5b32612e 100644
--- a/docs/bevy-parity.md
+++ b/docs/bevy-parity.md
@@ -4,7 +4,7 @@ Bevy v0.20.0's examples against their raea TSX ports (docs/control.feature FC0a)
don't edit. An example passes when every probed frame passes pixels (SSIM 0.98 and no 32 px tile off by more than 24 of 255) and cost (batch keys and
frame time at most 1.25x the example's). Wall time is one machine's, measured in the same run.
-Examples: **438**, ported **79**, passing **75**, excluded **16** (docs/bevy-parity/excluded.tsv), left **347**.
+Examples: **438**, ported **80**, passing **76**, excluded **16** (docs/bevy-parity/excluded.tsv), left **346**.
raea's frame ms is its update's plus the time React takes to step a frame for its 3D (step), which the example
doesn't pay.
@@ -135,6 +135,7 @@ doesn't pay.
| ui/ui_scaling | 10 | 0.999856 | 5 | 0 / 0 | 446 / 492 | 5 / 7 | 1 / 1 | 37.383 / 2.14 = 2.14 + 0 | yes | |
| ui/layout/anchor_layout | 10 | 0.997421 | 9 | 0 / 0 | 468 / 492 | 5 / 7 | 1 / 1 | 33.145 / 1.417 = 1.417 + 0 | yes | |
| ui/layout/size_constraints | 10 | 0.991466 | 19 | 0 / 0 | 608 / 492 | 5 / 7 | 1 / 1 | 31.358 / 0.993 = 0.993 + 0 | yes | |
+| ui/scroll_and_overflow/overflow_transform | 10 | 0.995397 | 12 | 0 / 0 | 447 / 492 | 5 / 7 | 1 / 1 | 41.134 / 1.724 = 1.724 + 0 | yes | |
## Excluded
diff --git a/docs/bevy-parity/results.jsonl b/docs/bevy-parity/results.jsonl
index 41c51906..83d3495d 100644
--- a/docs/bevy-parity/results.jsonl
+++ b/docs/bevy-parity/results.jsonl
@@ -122,3 +122,4 @@
{"example":"ui/ui_scaling","frame":10,"ssim":0.999856,"tile":5,"bevy":{"batch_keys":0,"entities":446,"extents":[],"frame":10,"frame_ms":37.383,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":2.14,"step_ms":null,"cost_ms":2.14},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/layout/anchor_layout","frame":10,"ssim":0.997421,"tile":9,"bevy":{"batch_keys":0,"entities":468,"extents":[],"frame":10,"frame_ms":33.145,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.417,"step_ms":null,"cost_ms":1.417},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
{"example":"ui/layout/size_constraints","frame":10,"ssim":0.991466,"tile":19,"bevy":{"batch_keys":0,"entities":608,"extents":[],"frame":10,"frame_ms":31.358,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":0.993,"step_ms":null,"cost_ms":0.993},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
+{"example":"ui/scroll_and_overflow/overflow_transform","frame":10,"ssim":0.995397,"tile":12,"bevy":{"batch_keys":0,"entities":447,"extents":[],"frame":10,"frame_ms":41.134,"materials":1,"mesh_entities":0,"meshes":5,"other_material":0,"visible":0},"raea":{"frame":17,"entities":492,"mesh_entities":0,"visible":0,"meshes":7,"materials":1,"batch_keys":0,"other_material":0,"extents":[],"frame_ms":1.724,"step_ms":null,"cost_ms":1.724},"pixels":true,"draws":true,"time":true,"pass":true,"why":""}
diff --git a/sdk/raea/bench/bevy-parity/ui/scroll_and_overflow/overflow_transform.tsx b/sdk/raea/bench/bevy-parity/ui/scroll_and_overflow/overflow_transform.tsx
new file mode 100644
index 00000000..c487c266
--- /dev/null
+++ b/sdk/raea/bench/bevy-parity/ui/scroll_and_overflow/overflow_transform.tsx
@@ -0,0 +1,56 @@
+// Bevy v0.20.0 examples/ui/scroll_and_overflow/overflow_transform.rs in raea's TSX: three nested square nodes (400,
+// 350, 300 px; 4 px borders of 0.7 white; each clipping its overflow) turning about their centres at their own speeds,
+// centred in the window; inside the last, an absolute navy box turned 45 degrees and breathing in scale, 20% rounded,
+// a light-blue 5 px border, a drop shadow 30 px down and right (blur 4) of the innermost green made darker, holding the
+// 400 px wide bevy_logo_dark_big.png and "transform + overflow" in 34 px FiraSans-Bold. Each turn and the scale are of
+// Bevy's elapsed time, its f32 sum of 1/60 s steps up to the frame. Bevy's Camera2d over the default clear colour is
+// the layered <Canvas3D>. In Bevy's default 1280 x 720 window.
+import type { ReactNode } from "react";
+import { AbsoluteFill, Composition, registerRoot, staticFile, useCurrentFrame } from "raea";
+import { Canvas3D } from "raea/3d";
+import { BorderRadius, BoxShadow, ImageNode, Node, Rot2, Text, UiRect, UiTransform, percent, px } from "raea/ui";
+import { Srgba } from "raea/color";
+
+// Time::elapsed_secs at frame f: f steps of 1/60 s, summed in f32
+function elapsedAt(f: number): number {
+ let t = 0;
+ for (let k = 1; k <= f; k++) t = Math.fround(t + Math.fround(16_666_667e-9));
+ return t;
+}
+
+const GREEN = new Srgba(0.15, 0.3, 0.25);
+
+function Layer({ size, rotation, speed, color, t, children }: { size: number; rotation: number; speed: number; color: Srgba; t: number; children?: ReactNode }) {
+ const turn = Math.fround(rotation + Math.fround(t * speed));
+ return (
+ <Node width={px(size)} height={px(size)} overflow={{ x: "Clip", y: "Clip" }} align_items="Center" justify_content="Center" border={UiRect.all(px(4))} background_color={color} border_color={new Srgba(1, 1, 1, 0.7)} ui_transform={UiTransform.from_rotation(Rot2.radians(turn))}>
+ {children}
+ </Node>
+ );
+}
+
+function Shot() {
+ const t = elapsedAt(useCurrentFrame());
+ const s = 1 + 0.75 * Math.sin(0.4 * t);
+ return (
+ <AbsoluteFill>
+ <Canvas3D layered clearColor="rgb(43, 44, 47)" />
+ <Node width={percent(100)} height={percent(100)} align_items="Center" justify_content="Center">
+ <Layer size={400} rotation={0.35} speed={0.18} color={new Srgba(0.12, 0.17, 0.22)} t={t}>
+ <Layer size={350} rotation={-0.5} speed={-0.4} color={new Srgba(0.24, 0.18, 0.32)} t={t}>
+ <Layer size={300} rotation={0.65} speed={0.55} color={GREEN} t={t}>
+ <Node flex_direction="Column" position_type="Absolute" margin={UiRect.AUTO} border_radius={BorderRadius.all(percent(20))} align_items="Center" justify_content="SpaceAround" border={UiRect.all(px(5))} padding={UiRect.all(px(5))}
+ box_shadow={BoxShadow.new(GREEN.darker(0.05), px(30), px(30), px(0), px(4))} background_color={new Srgba(0, 0, 128 / 255)} border_color={new Srgba(173 / 255, 216 / 255, 230 / 255)}
+ ui_transform={{ rotation: Rot2.degrees(45), scale: [s, s] }}>
+ <ImageNode image={staticFile("branding/bevy_logo_dark_big.png")} width={px(400)} />
+ <Text font={staticFile("fonts/FiraSans-Bold.ttf")} font_size={{ Px: 34 }} color={new Srgba(1, 1, 1)}>transform + overflow</Text>
+ </Node>
+ </Layer>
+ </Layer>
+ </Layer>
+ </Node>
+ </AbsoluteFill>
+ );
+}
+
+registerRoot(() => <Composition id="main" component={Shot} durationInFrames={11} fps={60} width={1280} height={720} />);
diff --git a/sdk/raea/conformance/ui-transform.test.tsx b/sdk/raea/conformance/ui-transform.test.tsx
new file mode 100644
index 00000000..3c28a1bd
--- /dev/null
+++ b/sdk/raea/conformance/ui-transform.test.tsx
@@ -0,0 +1,64 @@
+// docs/control.feature FC0a: bevy_ui's UiTransform and BoxShadow on the page (ui/scroll_and_overflow/overflow_transform),
+// and bevy_color's Luminance darker and lighter.
+import { describe, expect, test } from "bun:test";
+import { BoxShadow, Node, Rot2, UiTransform, Val2, percent, px } from "raea/ui";
+import { LinearRgba, Srgba } from "raea/color";
+import { renderFrame } from "../src/test";
+
+const html = (el: React.ReactElement) => renderFrame(el, { frame: 0, width: 320, height: 240, fps: 30, durationInFrames: 30 });
+
+describe("UiTransform: a node moved, turned and scaled about its centre after layout", () => {
+ test("translation, then rotation (clockwise), then scale, as CSS's transform", () => {
+ const out = html(<Node ui_transform={{ translation: Val2.px(10, -5), rotation: Rot2.degrees(90), scale: [2, 0.5] }} />);
+ const m = out.match(/transform:translate\(10px, -5px\) rotate\(([\d.]+)rad\) scale\(2, 0.5\)/);
+ expect(m).not.toBeNull();
+ expect(Number(m![1])).toBeCloseTo(Math.PI / 2, 6);
+ });
+ test("a percent translation is of the node's own size, and auto is 0", () => {
+ expect(html(<Node ui_transform={UiTransform.from_translation(Val2.new(percent(50), "auto"))} />)).toContain("transform:translate(50%, 0px)");
+ });
+ test("Rot2's radians, degrees and turn fractions are one angle; identity adds no transform", () => {
+ const angle = (r: Rot2) => Math.atan2(r.sin, r.cos);
+ expect(angle(Rot2.degrees(45))).toBeCloseTo(Math.PI / 4, 6);
+ expect(angle(Rot2.turn_fraction(-0.25))).toBeCloseTo(-Math.PI / 2, 6);
+ expect(angle(Rot2.radians(0.35))).toBeCloseTo(0.35, 6);
+ expect(html(<Node ui_transform={UiTransform.IDENTITY} />)).not.toContain("transform");
+ expect(html(<Node ui_transform={UiTransform.from_scale([1, 1])} />)).not.toContain("transform");
+ });
+ test("a bad transform throws", () => {
+ expect(() => html(<Node ui_transform={{ scale: [NaN, 1] }} />)).toThrow(/scale/);
+ expect(() => html(<Node ui_transform={{ rotation: { cos: "1", sin: 0 } as never }} />)).toThrow(/rotation/);
+ });
+});
+
+describe("BoxShadow: drop shadows under a node", () => {
+ test("Bevy's blur radius (its Gaussian's deviation) is half CSS's; offsets as they are; listed top first", () => {
+ const out = html(<Node box_shadow={[
+ { color: new Srgba(1, 0, 0), x_offset: px(1), y_offset: px(2), spread_radius: px(0), blur_radius: px(3) },
+ { color: new Srgba(0, 0, 1), x_offset: px(-4), y_offset: px(5), spread_radius: px(0), blur_radius: px(0) },
+ ]} />);
+ expect(out).toMatch(/box-shadow:-4px 5px 0px 0px rgba\(0, 0, 255, 1\), 1px 2px 6px 0px rgba\(255, 0, 0, 1\)/);
+ expect(html(<Node box_shadow={BoxShadow.new(new Srgba(0, 0, 0), px(30), px(30), px(0), px(4))} />)).toMatch(/box-shadow:30px 30px 8px 0px /);
+ });
+ test("a spread, a percent or a negative blur is refused, not drawn wrong", () => {
+ expect(() => html(<Node box_shadow={BoxShadow.new(new Srgba(0, 0, 0), px(1), px(1), px(2), px(4))} />)).toThrow(/spread_radius/);
+ expect(() => html(<Node box_shadow={BoxShadow.new(new Srgba(0, 0, 0), percent(20), px(1), px(0), px(4))} />)).toThrow(/x_offset/);
+ expect(() => html(<Node box_shadow={BoxShadow.new(new Srgba(0, 0, 0), px(1), px(1), px(0), px(-1))} />)).toThrow(/blur_radius/);
+ });
+});
+
+describe("Luminance: darker and lighter mix toward black or white in linear light", () => {
+ test("darker lowers the linear luminance by the amount and keeps its chromaticity", () => {
+ const c = new Srgba(0.15, 0.3, 0.25);
+ const [a, b] = [LinearRgba.from(c), LinearRgba.from(c.darker(0.05))];
+ expect(b.luminance()).toBeCloseTo(a.luminance() - 0.05, 4);
+ expect(b.green / b.red).toBeCloseTo(a.green / a.red, 4);
+ expect(c.darker(1).red).toBe(0);
+ });
+ test("lighter mixes toward white, at most to white", () => {
+ const a = LinearRgba.rgb(0.2, 0.1, 0.05);
+ expect(a.lighter(0.1).luminance()).toBeCloseTo(a.luminance() + 0.1, 5);
+ const w = a.lighter(2);
+ expect([w.red, w.green, w.blue]).toEqual([1, 1, 1]);
+ });
+});
diff --git a/sdk/raea/src/ui.ts b/sdk/raea/src/ui.ts
index 90145fd1..44338061 100644
--- a/sdk/raea/src/ui.ts
+++ b/sdk/raea/src/ui.ts
@@ -9,3 +9,4 @@ export * from "@raea/video/panel";
export { Node, GhostNode, Text, TextSpan, TextShadow, Text2d, UiScale, Viewport, UiTargetCamera, ImageNode, InlineImage, type TextureSlicer, type SliceScaleMode, ImagePlugin, FontVariationTag, TextureAtlasLayout, type ImageNodeProps, px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type NodeProps, type TextProps, type TextStyleProps, type TextRunProps, type Text2dProps, type Val } from "@raea/render/bevy3d";
export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "@raea/render/bevy3d";
export { GridTrack, RepeatedGridTrack, GridPlacement, type GridTrackRepetition, type GridAutoFlow, type MinTrackSizingFunction, type MaxTrackSizingFunction, FontSource, type GenericFontFamily } from "@raea/render/bevy3d";
+export { Rot2, Val2, UiTransform, BoxShadow, type ShadowStyle } from "@raea/render/bevy3d";
diff --git a/sdk/render/src/bevy3d.tsx b/sdk/render/src/bevy3d.tsx
index c368f98a..ce0b1cd3 100644
--- a/sdk/render/src/bevy3d.tsx
+++ b/sdk/render/src/bevy3d.tsx
@@ -33,4 +33,5 @@ export { ImageNode, InlineImage, ImagePlugin, TextureAtlasLayout, type TextureSl
export { px, percent, vw, vh, vmin, vmax, auto, UiRect, BorderRadius, CornerRadius, Overflow, OverflowClipMargin, type Val } from "./bevy3d/ui-val";
export { LinearGradient, RadialGradient, ConicGradient, ColorStop, AngularColorStop, UiPosition, type Gradient, type RadialGradientShape, type InterpolationColorSpace } from "./bevy3d/ui-gradient";
export { GridTrack, RepeatedGridTrack, GridPlacement, type GridTrackRepetition, type GridAutoFlow, type MinTrackSizingFunction, type MaxTrackSizingFunction } from "./bevy3d/ui-grid";
+export { Rot2, Val2, UiTransform, BoxShadow, type ShadowStyle } from "./bevy3d/ui-transform";
export { FontSource, type GenericFontFamily } from "./bevy3d/ui-font";
diff --git a/sdk/render/src/bevy3d/colors.ts b/sdk/render/src/bevy3d/colors.ts
index c3851627..414b22b1 100644
--- a/sdk/render/src/bevy3d/colors.ts
+++ b/sdk/render/src/bevy3d/colors.ts
@@ -24,6 +24,14 @@ export class Srgba {
return s;
}
/** Bevy's Alpha::with_alpha */
+ /** Bevy's Luminance::darker on an Srgba: its linear colour's, encoded again */
+ darker(amount: number): Srgba {
+ return LinearRgba.from(this).darker(amount).to_srgba();
+ }
+ /** Bevy's Luminance::lighter on an Srgba: its linear colour's, encoded again */
+ lighter(amount: number): Srgba {
+ return LinearRgba.from(this).lighter(amount).to_srgba();
+ }
with_alpha(alpha: number): Srgba {
const s = new Srgba(this.red, this.green, this.blue, alpha);
s[MADE_FROM] = this[MADE_FROM];
@@ -69,6 +77,26 @@ export class LinearRgba {
const g = (c: number) => (c <= 0 ? c : Math.fround(linearToSrgb(c)));
return new Srgba(g(this.red), g(this.green), g(this.blue), this.alpha);
}
+ /** Bevy's Luminance::luminance: Rec. 709's weights over the linear channels */
+ luminance(): number {
+ return this.red * 0.2126 + this.green * 0.7152 + this.blue * 0.0722;
+ }
+ /** Bevy's Luminance::darker: mixed toward black until its luminance is `amount` lower (at least 0) */
+ darker(amount: number): LinearRgba {
+ return this.lightness(-amount);
+ }
+ /** Bevy's Luminance::lighter: mixed toward white until its luminance is `amount` higher (at most 1) */
+ lighter(amount: number): LinearRgba {
+ return this.lightness(amount);
+ }
+ private lightness(amount: number): LinearRgba {
+ if (!Number.isFinite(amount)) throw new RangeError(`LinearRgba.darker/lighter: amount is a finite number, got ${amount}`);
+ const l = this.luminance();
+ const t = Math.max(0, Math.min(1, l + amount));
+ if (t < l) return this.mix(new LinearRgba(0, 0, 0, this.alpha), (l - t) / l);
+ if (t > l) return this.mix(new LinearRgba(1, 1, 1, this.alpha), (t - l) / (1 - l));
+ return new LinearRgba(this.red, this.green, this.blue, this.alpha);
+ }
/** Bevy's Mix: each channel lerped, in f32 */
mix(o: LinearRgba, t: number): LinearRgba {
const m = (a: number, b: number) => Math.fround(Math.fround(a * Math.fround(1 - t)) + Math.fround(b * t));
diff --git a/sdk/render/src/bevy3d/ui-transform.ts b/sdk/render/src/bevy3d/ui-transform.ts
new file mode 100644
index 00000000..390a156e
--- /dev/null
+++ b/sdk/render/src/bevy3d/ui-transform.ts
@@ -0,0 +1,89 @@
+// bevy_ui's UiTransform (a node turned, scaled and moved about its centre after layout, which it doesn't change) and
+// BoxShadow (drop shadows under a node) as the page's CSS transform and box-shadow.
+import { checkVal, colorCss, type Val } from "./ui-val";
+
+/** bevy_math's Rot2: a rotation by its cosine and sine; positive turns a UI node clockwise. @bevy bevy_math::Rot2 */
+export interface Rot2 { cos: number; sin: number }
+const rot = (r: number): Rot2 => {
+ if (!Number.isFinite(r)) throw new RangeError(`Rot2: an angle is a finite number, got ${r}`);
+ return { cos: Math.fround(Math.cos(r)), sin: Math.fround(Math.sin(r)) };
+};
+export const Rot2 = {
+ IDENTITY: { cos: 1, sin: 0 } as Rot2,
+ radians: (r: number): Rot2 => rot(r),
+ degrees: (d: number): Rot2 => rot((d * Math.PI) / 180),
+ /** a fraction of a full turn (0.25 is a quarter) */
+ turn_fraction: (f: number): Rot2 => rot(f * 2 * Math.PI),
+};
+
+/** bevy_ui's Val2: a translation's x and y (a percent of the node's own width and height; auto is 0).
+ * @bevy bevy_ui::ui_transform::Val2 */
+export interface Val2 { x: Val; y: Val }
+export const Val2 = {
+ ZERO: { x: "0px", y: "0px" } as Val2,
+ px: (x: number, y: number): Val2 => ({ x: `${x}px`, y: `${y}px` }),
+ percent: (x: number, y: number): Val2 => ({ x: `${x}%`, y: `${y}%` }),
+ new: (x: Val, y: Val): Val2 => ({ x, y }),
+};
+
+/** bevy_ui's UiTransform: the node scaled, then turned, then moved, about its centre, after layout.
+ * @bevy bevy_ui::ui_transform::UiTransform */
+export interface UiTransform { translation?: Val2; scale?: [number, number]; rotation?: Rot2 }
+export const UiTransform = {
+ IDENTITY: {} as UiTransform,
+ from_translation: (translation: Val2): UiTransform => ({ translation }),
+ from_rotation: (rotation: Rot2): UiTransform => ({ rotation }),
+ from_scale: (scale: [number, number]): UiTransform => ({ scale }),
+};
+
+/** A UiTransform as CSS's transform (its origin is CSS's default, the box's centre, as Bevy's), or undefined at identity. */
+export function transformCss(who: string, t: UiTransform): string | undefined {
+ if (!t || typeof t !== "object") throw new TypeError(`${who}: ui_transform is a UiTransform (UiTransform.from_rotation(Rot2.degrees(45))), got ${JSON.stringify(t)}`);
+ const parts: string[] = [];
+ if (t.translation !== undefined) {
+ const v = (k: "x" | "y") => (t.translation![k] === "auto" ? "0px" : checkVal(who, `ui_transform.translation.${k}`, t.translation![k]));
+ const [x, y] = [v("x"), v("y")];
+ if (parseFloat(x) !== 0 || parseFloat(y) !== 0) parts.push(`translate(${x}, ${y})`);
+ }
+ if (t.rotation !== undefined) {
+ const { cos, sin } = t.rotation;
+ if (!Number.isFinite(cos) || !Number.isFinite(sin)) throw new TypeError(`${who}: ui_transform.rotation is a Rot2 (Rot2.degrees(45)), got ${JSON.stringify(t.rotation)}`);
+ const a = Math.atan2(sin, cos);
+ if (a !== 0) parts.push(`rotate(${a}rad)`);
+ }
+ if (t.scale !== undefined) {
+ const [sx, sy] = t.scale;
+ if (!Number.isFinite(sx) || !Number.isFinite(sy)) throw new TypeError(`${who}: ui_transform.scale is [x, y], got ${JSON.stringify(t.scale)}`);
+ if (sx !== 1 || sy !== 1) parts.push(`scale(${sx}, ${sy})`);
+ }
+ return parts.length ? parts.join(" ") : undefined;
+}
+
+/** bevy_ui's ShadowStyle: one drop shadow's colour, offset, spread and blur. @bevy bevy_ui::ShadowStyle */
+export interface ShadowStyle { color: unknown; x_offset: Val; y_offset: Val; spread_radius: Val; blur_radius: Val }
+/** bevy_ui's BoxShadow: drop shadows under a node, drawn back to front. @bevy bevy_ui::BoxShadow */
+export type BoxShadow = ShadowStyle[];
+export const BoxShadow = {
+ new: (color: unknown, x_offset: Val, y_offset: Val, spread_radius: Val, blur_radius: Val): BoxShadow => [{ color, x_offset, y_offset, spread_radius, blur_radius }],
+};
+
+const pxOf = (who: string, k: string, v: Val) => {
+ const s = checkVal(who, k, v);
+ if (!s.endsWith("px")) throw new TypeError(`${who}: ${k} in px is what a shadow takes for now (a percent of the node's size is to do), got ${s}`);
+ return parseFloat(s);
+};
+
+/** A BoxShadow as CSS's box-shadow. Bevy's blur radius is its Gaussian's standard deviation, CSS's twice that. Bevy
+ * spreads the shadow by spread_radius across its width and scales its height and corners by the same ratio, which
+ * CSS's spread (even on every side, corners grown by it) matches only at zero; any other spread is to do. */
+export function shadowCss(who: string, b: BoxShadow): string {
+ if (!Array.isArray(b)) throw new TypeError(`${who}: box_shadow is a BoxShadow (BoxShadow.new(color, px(30), px(30), px(0), px(4))), got ${JSON.stringify(b)}`);
+ // CSS lists the shadow on top first, Bevy draws its list back to front
+ return [...b].reverse().map((s, i) => {
+ const k = `box_shadow[${b.length - 1 - i}]`;
+ if (pxOf(who, `${k}.spread_radius`, s.spread_radius) !== 0) throw new TypeError(`${who}: ${k}.spread_radius other than 0 is to do (Bevy scales the shadow's height and corners by the width's spread ratio)`);
+ const blur = pxOf(who, `${k}.blur_radius`, s.blur_radius);
+ if (blur < 0) throw new RangeError(`${who}: ${k}.blur_radius is at least 0, got ${blur}`);
+ return `${pxOf(who, `${k}.x_offset`, s.x_offset)}px ${pxOf(who, `${k}.y_offset`, s.y_offset)}px ${blur * 2}px 0px ${colorCss(who, `${k}.color`, s.color)}`;
+ }).join(", ");
+}
diff --git a/sdk/render/src/bevy3d/ui.tsx b/sdk/render/src/bevy3d/ui.tsx
index 27994354..0715c3f9 100644
--- a/sdk/render/src/bevy3d/ui.tsx
+++ b/sdk/render/src/bevy3d/ui.tsx
@@ -12,6 +12,7 @@ import {
import { LinearRgba, type Srgba } from "./colors";
import { gradientsCss, gradientsOpaque, type Gradient } from "./ui-gradient";
import { gridCss, type GridAutoFlow, type GridPlacement, type GridTrack, type RepeatedGridTrack } from "./ui-grid";
+import { shadowCss, transformCss, type BoxShadow, type UiTransform } from "./ui-transform";
import type { TransformValue } from "./core";
import { eulerOf } from "../3d/model";
import { useVideoConfig } from "@raea/app/clock";
@@ -63,6 +64,10 @@ export interface NodeProps {
/** Visibility: Inherited (its parent's, the default), Hidden (laid out, not drawn) or Visible (drawn under a hidden
* parent), as CSS's visibility inherits */
visibility?: "Inherited" | "Hidden" | "Visible";
+ /** UiTransform: turned, scaled and moved about its centre after layout */
+ ui_transform?: UiTransform;
+ /** BoxShadow: drop shadows under it, back to front */
+ box_shadow?: BoxShadow;
/** FixedNode: laid out as a root wherever it is in the tree (its own viewport, the window's), drawn with its parent */
fixed?: boolean;
children?: ReactNode;
@@ -110,6 +115,8 @@ export function nodeCss(who: string, p: NodeProps, back?: Backdrop): { css: CSSP
if (p.aspect_ratio !== undefined) s.aspectRatio = p.aspect_ratio;
gridCss(who, p, s);
if (p.visibility !== undefined && p.visibility !== "Inherited") s.visibility = keyword(who, "visibility", p.visibility, ["Hidden", "Visible"]);
+ if (p.ui_transform !== undefined) s.transform = transformCss(who, p.ui_transform);
+ if (p.box_shadow !== undefined && p.box_shadow.length) s.boxShadow = shadowCss(who, p.box_shadow);
// every node a stacking context, so a ZIndex ranks it among its siblings above their parent, as bevy_ui stacks
// them; a GlobalZIndex ranks it in the root's (raea's Blitz hoists it past every other, layout/paint_tree.rs)
s.zIndex = p.global_z_index ?? p.z_index ?? 0;
diff --git a/sdk/skills/raea/reference/sdk.md b/sdk/skills/raea/reference/sdk.md
index 960b6074..cc41fbba 100644
--- a/sdk/skills/raea/reference/sdk.md
+++ b/sdk/skills/raea/reference/sdk.md
@@ -99,7 +99,7 @@ with a capital, hooks with `use`. A component's props are in its file.
## `raea/ui` (sdk/raea/src/ui.ts)
-`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontSource`, `FontVariationTag`, `GhostNode`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `Viewport`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`
+`AbsoluteFill`, `AngularColorStop`, `BorderRadius`, `BoxShadow`, `ColorStop`, `ConicGradient`, `CornerRadius`, `FontSource`, `FontVariationTag`, `GhostNode`, `GridPlacement`, `GridTrack`, `ImageNode`, `ImagePlugin`, `InlineImage`, `LinearGradient`, `Node`, `Overflow`, `OverflowClipMargin`, `RadialGradient`, `RepeatedGridTrack`, `Rot2`, `Text`, `Text2d`, `TextShadow`, `TextSpan`, `TextureAtlasLayout`, `UiPosition`, `UiRect`, `UiScale`, `UiTargetCamera`, `UiTransform`, `Val2`, `Viewport`, `auto`, `percent`, `px`, `vh`, `vmax`, `vmin`, `vw`
## `raea/video` (sdk/raea/src/video.ts)