Skip to main content

Crate day_piece_remote_image

Crate day_piece_remote_image 

Source
Expand description

day-piece-remote-image — an EXTERNAL Day Piece (DESIGN.md §15): a NATIVE image view that decodes encoded bytes (PNG/JPEG) supplied reactively and draws them, with a placeholder rectangle while the source is empty. This is the image primitive a Matrix client needs — avatars and inline image messages — where the app fetches mxc:// bytes off the UI thread via the SDK and pushes them into a signal; this piece only turns bytes into a native image.

Unlike day’s built-in image (which loads a bundled asset by name), the source here is Signal<Option<Arc<Vec<u8>>>>: None shows the placeholder color; Some(bytes) decodes and displays. The Arc<Vec<u8>> is shared, so pushing a large buffer from a background decode is a refcount bump, not a copy. The piece is a growing leaf that fills its frame (constrain it with .frame(w, h)); avatars occupy their box even before any bytes arrive.

let avatar: Signal<Option<Arc<Vec<u8>>>> = Signal::new(None);
// …app pushes decoded bytes later: avatar.set(Some(Arc::new(png_bytes)));…
remote_image(avatar).circle().placeholder_color(Color::hex(0xD0D0D0)).frame(40.0, 40.0)

Structs§

RemoteImage
A native image view whose content mirrors source (a Signal<Option<Arc<Vec<u8>>>>). Shape it with .circle() / .rounded(r), scale it with .content_mode(_), and set the empty-state color with .placeholder_color(_).
RemoteImageProps
Full props (realize). bytes seeds the view; all four are applied at build. Only bytes changes after build, via RemoteImagePatch::SetBytes.

Enums§

Clip
How the piece (image AND placeholder) is clipped to its frame.
ContentMode
How the decoded image is scaled into the piece’s frame.
RemoteImagePatch
The single imperative update: replace the displayed bytes (or clear to the placeholder).

Constants§

KIND

Functions§

remote_image
remote_image(source) — a native image view that decodes and displays the bytes held in source, showing the placeholder color whenever source is None.
remote_image_url
remote_image_url(url)remote_image with the fetch built in: the bytes are downloaded once through the PLATFORM HTTP stack (day-part-http — system proxies/VPN/Low-Data aware, docs/http.md) on a background completion, and pushed into the piece’s own signal via a Setter (so a late arrival after the piece is disposed is a harmless no-op). The placeholder shows until the bytes land; a failed fetch (or non-2xx status) leaves the placeholder.
Day API ↩ Guides· daybrite.dev