Expand description
The backgroundImage style: an image painted as part of a node’s own
background stack — over backgroundColor and backgroundGradient, under
the node’s content (bevy_ui’s fixed per-node paint order) — by inserting an
ImageNode on the same entity. Never NodeImageMode::Auto, so the image
contributes nothing to layout and a late-loading asset causes no reflow.
The build needs AssetServer, which apply_style_masked doesn’t hold, so
apply_background_image is called from the reconcile sites (and the
interaction restyle systems) instead of from an apply_style_masked arm —
the same split as an image element’s image_node build. Elements that
own their entity’s ImageNode (image, canvas, portal) are guarded by
JsBridge::foreign_images at those call sites.
Structs§
- Background
Tile Scale - The logical tile scale of a repeat-mode background image (
scale, default1.0).sync_background_tile_scalemultiplies it by the node’s scale factor intoNodeImageMode::Tiled.stretch_value, so1.0tiles at the texture’s own size in logical px on every display (CSS semantics). - RBackground
Texture - Marks a node whose background image samples a render target registered in
crate::portal::RenderTargets.bind_background_textureskeeps the entity’sImageNodepointed at the registry’s texture for this name (transparent placeholder while unregistered — the node binds late, like a<portal>). Unlike a portal, a background never becomes the target’sbinder, soResolution::Autotargets stay at their initial size unless a portal also shows them — preferResolution::Fixedtargets here.
Functions§
- apply_
background_ image - Apply the style’s
backgroundImageonto the entity: insert/update or remove theImageNode(plus theRBackgroundTexture/BackgroundTileScalemarkers) per the spec. Skips entirely unless theBG_IMAGEgroup is dirty. Callers guarantee the entity’sImageNodeis not element-owned (seeJsBridge::foreign_images); on a node that never had the style, the removes are no-ops (same pattern as theBackgroundColorarm inapply_style_masked). - bind_
background_ textures - Point every background-texture node’s
ImageNodeat the registry texture for itsRBackgroundTexturename (or the shared transparent placeholder while unregistered) — thebackgroundImageanalogue ofbind_portals, minus thebinderrecording (that is portalResolution::Autosizing semantics; a background never sizes its target). Only writes on change; a real swap marks layer content dirty so an enclosing cached layer repaints the late-bound pixels. - sync_
background_ tile_ scale - Keep a repeat-mode background’s
stretch_valueequal toscale × scale factor, soscale: 1tiles at the texture’s own size in logical px on every display (CSS semantics; bevy’s tiling is in physical terms). Reacts toChanged<ImageNode>too — every restyle (delta, hover flip) re-inserts the node with the logical value — and settles via compare-before-write (the corrected write’s ownChangedecho no-ops on the next pass).