Expand description
The wire protocol shared between the JS reconciler and the Bevy side.
Everything here derives serde so deno_core’s serde_v8 can convert
directly between the plain JS objects the reconciler builds and these Rust
types — no JSON strings on the hot path. Ops only ever flow JS -> Rust, so
they need Deserialize only; UiEvent flows Rust -> JS and is Serialize.
Wire strings are decoded once, here at the serde boundary — never
re-parsed on apply. The unit-bearing types (Length/Angle/Time/
FontSize) parse into their own wire types, and the enum-like style fields
(display/align*/flex*/grid tracks/…) decode directly into the
bevy_ui/bevy_text values they drive, via field-level deserialize_with
(which sidesteps the orphan rule), so applying a style in [crate::ui_map]
is a plain field copy. A malformed string must not fail the whole batch
(one typo would abort the entire commit and trigger a reload), so every
deserializer falls back to the bevy default and emits a
tracing::warn! naming the bad value (tracing reaches the same log sink
bevy_log drains).
Re-exports§
pub use crate::canvas::DrawCmd;
Modules§
- style_
groups - Bit flags naming the groups of work [
crate::ui_map::apply_style] (and the update reconciler) derive from aStyle. EachStylefield belongs to the group(s) whose output reads it (see [with_style_fields]); a delta update ORs the groups of its touched fields into aStyleDirtymask so the apply path can skip every group the delta provably didn’t affect.
Structs§
- Angle
- An angle, parsed from the wire as a number (read as degrees, the CSS
convention) or a unit string (
"45deg","1.5rad","0.25turn","100grad"). Stored internally as radians — the unit Bevy’s gradient and transform APIs want. - Angular
Stop - A single color stop for a conic gradient.
angleis the stop’s angle in degrees (absent → auto-spaced);hintas inGradientStop. - Atlas
Spec - A uniform sprite-sheet grid plus the selected cell. Mirrors
TextureAtlasLayout::from_grid(tile size, columns, rows, optional padding / offset, all in source-texture pixels) +TextureAtlas.index. Bevy-free; turned into a cachedTextureAtlasLayoutasset inui_map. - Border
Color Spec - Border color: a single CSS color applied to all four sides, or a
{ top, right, bottom, left }object setting sides individually. Omitted sides decode toNone(painted transparent — bevy’sBorderColordefault). - BoxShadow
Spec - A single drop shadow.
- Conic
Gradient Spec - Filter
Spec - A CSS-like
filter: each field is one filter function, mirroring CSS naming. Every field is optional; unset means identity (no effect). Amounts follow the CSS convention:brightness/contrast/saturateare multipliers (1.0= identity),grayscale/sepia/invertare0.0..=1.0blends (0= identity),bluris a radius (aLengthin px), andhueRotateis anAngle. The functions are applied in a fixed canonical order (blur → brightness → contrast → saturate → grayscale → sepia → invert → hueRotate), not the declared order, so listing the same function twice is not supported. See [crate::filter]. - Gradient
Stop - A single color stop for a linear/radial gradient.
positionis where the color sits along the gradient line (aLength); absent → auto-spaced.hintis the0.0..=1.0interpolation midpoint between this stop and the next (default0.5). - Linear
Gradient Spec - Outline
Spec - Outline drawn around (outside) the node’s border box.
- Props
- Props for a host element. Event handlers never cross the boundary — the
reconciler replaces them with booleans (e.g.
onClick: true) and keeps the actual function in a JS-side map. Visual styling lives entirely inStyle; the fields here are content/attribute level. - Props
Dirty - Which parts of a
Propsa delta update touched; drives which of the reconciler’sapply_*helpers run. Style granularity lives inStyleDirty; the other flags are per prop group. - Radial
Gradient Spec - Rect
- Four sides (or corners), each a
Length. Accepts a number, a CSS shorthand string, or a{ top, right, bottom, left }object on the wire. - Slice
Spec - 9-slice scaling parameters, mirroring
bevy_sprite::TextureSlicer. - Source
Rect - A source sub-rect in texture pixels: top-left (
x,y) pluswidth/height. Converted to abevy_math::Rect(min/max corners) inui_map. - Style
- A CSS-like style object mapped onto
bevy_ui::Nodeand its sibling visual components. Every field is optional; unset fields keep Bevy’s defaults. - Style
Dirty - Which
style_groupsa delta update touched.ALL(every bit set) is the full-reapply mask used by non-delta paths. - Text
Shadow Spec - A single text drop shadow.
offsetX/offsetYare displacement in logical pixels (absent → bevy’s default of4.0);colordefaults to bevy’s translucent black when unset. - Tiled
Spec "tiled"scaling: the whole image repeats once stretched beyondstretch_value.- Time
- A time/duration, parsed from the wire as a number (read as milliseconds,
the JS-facing unit) or a unit string (
"200ms","0.2s"). Stored as seconds — the unit the animations engine and the transition driver consume. - Transform
- A static 2D transform mirroring the animated transform channels. Every field
is optional; unset channels stay at identity (no translation, unit scale, no
rotation).
scaleis uniform;scaleX/scaleYoverride a single axis. - UiEvent
- An interaction event sent from Bevy back into JS, where the reconciler dispatches it to the matching React handler.
- Update
Events - The “act now” props of an update, split from the retained state: pushed into the live widget once and never stored, so an unrelated later delta can’t replay them (re-push a controlled value, re-clone a canvas display list). Absent fields mean “no event”, exactly like the pre-delta protocol.
Enums§
- BoxShadow
List - A
boxShadowvalue: one shadow or a stacked list (CSSbox-shadow: a, b, …). - Font
Size - A font size mirroring
bevy_text::FontSize, parsed from the wire as a number (logical pixels) or a unit string ("24px","100vw"/vh/vmin/vmax,"1.5rem").remis relative to bevy’sRemSizeresource (default 20px). (CSSemhas nobevy_textequivalent, so it is not accepted.) - Gradient
List - A
backgroundGradient/borderGradientvalue: one gradient or a layered list. - Gradient
Spec - One gradient, discriminated by its
typefield on the wire. - Image
Mode - How an
imagefits its node. A bare string ("auto"/"stretch") maps to the trivialbevy_uimodes; thetype-tagged object forms map to bevy’s 9-slice ("sliced") and"tiled"scaling. Bevy-free; converted toNodeImageModeinui_map. - Image
Mode Spec - The object forms of
ImageMode, discriminated by theirtypefield. - Length
- A length value mirroring
bevy_ui::Val, parsed from the wire form (a number is logical pixels; a string carries an explicit unit). - Letter
Spacing Spec - Letter spacing for a
<text>. A bare number is logical pixels; a string carries a unit ("2px","0.1rem"/"0.1em"for a font-size multiple, or"normal");{ "rem": n }is a multiple of the font size (legacy object form). - Line
Height Spec - Line height for a
<text>. A bare number is a multiple of the font size (RelativeToFont); a string carries a unit ("20px"absolute,"1.5"/"1.5em"a multiple);{ "px": n }is an absolute pixel height (legacy object form). - Op
- A single mutation produced by the React reconciler during a commit. The
reconciler batches a
Vec<Op>per commit and flushes it across the boundary in one call. - Outbound
- Everything that flows Bevy -> JS over the single outbound channel. Internally
tagged (
t) soserde_v8produces a plain JS object the JS event loop canswitchon. Each variant serializes to a map, as internal tagging requires. - Radial
Shape Spec - The size/shape of a radial gradient. Either a keyword
(
"closestSide" | "farthestSide" | "closestCorner" | "farthestCorner", default"closestCorner") or an explicit{ circle }/{ ellipse }. - Response
Result - The outcome of a React -> Bevy request. Internally tagged (
status) so JS readsresult.status === "ok". The error is a message, surfaced to JS as a rejected promise — the typed success value is the only thing in the schema. - Slice
Border - 9-slice border insets: a single number (uniform) or per-side, in source-texture pixels.
- Slice
Scale - How a 9-slice section scales when resized:
"stretch"(the keyword) or{ tile }, wheretileis the repeatstretch_value.
Constants§
Type Aliases§
- Color
Space - Color space the gradient interpolates in (
"oklab"(default),"oklch","oklchLong","srgb","linearRgb","hsl","hslLong","hsv","hsvLong"). - Gradient
Position - Radial/conic gradient center, given as a named anchor (
"center","top","topLeft", …). ArbitraryVal-offset centers are not yet supported. - NodeId
- Stable identity for a node, assigned by the JS reconciler.
0is reserved for the root container (the Bevy UI root entity).