Skip to content
QuaUI
On this page

Media and layer effects

Supply images, audio, video and WGSL effects while keeping resource and player lifetimes in the host.

Images, audio and video

This JSX fragment uses Panel from @quajs/quaui. QuaUI also exports Image, Audio and Video components. In Rust, start with image("cover", "media/cover.png").size(80.0, 80.0).label("Cover") or use the audio and video constructors.

TSX
<Panel id="media"> <img id="cover" src="media/cover.png" width={80} height={80} alt="Cover" /> <video id="clip" src="media/intro.mp4" width={320} height={180} objectFit="contain" muted autoplay /> <audio id="voice" src="media/voice.wav" volume={0.5} /></Panel>

Media nodes carry an asset type, name and package provenance. A DOM host can lease asset URLs. Scene hosts resolve images through resolveImage and bind players through presentMedia. A stable node ID lets an update retain the same video player and playback position. Release resources when removing a node. UiSurfaceMedia describes autoplay, looping, mute, volume and playback rate. The host supplies decoding and audio output.

Apply WGSL to a subtree

A TSX element's shaders array and Rust's Element::shader(LayerShader { .. }) describe the same effects. In declaration order, each effect receives a composited texture of the element and its children. This function fades to grayscale as progress increases.

WGSL
fn effect(uv: vec2<f32>) -> vec4<f32> { let pixel = sampleLayer(uv); let gray = dot(pixel.rgb, vec3<f32>(0.2126, 0.7152, 0.0722)); return vec4<f32>(mix(pixel.rgb, vec3<f32>(gray), progress), pixel.a);}

uv runs from zero at the top left to one at the bottom right. Input and output are premultiplied RGBA. The host drives progress, four numeric params, timing and compositing. Enable the Rust crate's wgpu feature to call shader_pipeline::compile on the host's device. DOM and scene adapters display the ordinary element. Executing WGSL requires a supporting wgpu host.