Skip to content
  1. Docs
  2. enzUI framework
  3. Developers

Media and images

Images, animated images and SVG, icons, image viewing and cropping, video and media controls, and the services behind them.

The media widgets show pictures, video and the surfaces drawn over them. Playback widgets do not own a decoder: they are driven by a snapshot of media state, so the same transport bar works over any backend. See every widget in the widget catalog.

The gallery's Images and SVG page

Images

enz_image(path) shows a raster image; enz_image_handle(handle) takes an iced image handle you already decoded.

rust
use enzui_widgets::image::{EnzImageFit, enz_image};

enz_image("cover.jpg")
    .fit(EnzImageFit::Contain)
    .radius(12.0)
    .alt_text("Album cover")
    .into_element()

EnzImageFit is Cover (the default: fill the slot, cropping overflow), Contain (letterbox), Fill (stretch) or native size. .alt_text(..) gives the image an accessible name.

WidgetUse
enz_async_image_viewThe lifecycle of an asynchronous image request: loading skeleton, decoded image, or failure
enz_animated_imageA GIF, APNG or animated WebP that plays
svg_image::enz_svgAn SVG that can follow the theme's ink, with an accessible label
enz_animated_svgAn SVG playing its SMIL and CSS animations
enz_image_viewerAn inspectable image with a controlled zoom and pan transform
enz_image_cropperA controlled crop selection over the image viewer
enz_annotation_overlayDraw, preview, commit and hit-test annotations over a picture
enz_avatarA user picture or initials
enz_qrA themed QR code

Animated images and SVG

AnimatedFrames::decode reads a GIF, APNG or animated WebP once into frames and delays (off the UI thread for large files, for example in a Task::perform), and enz_animated_image shows them. Every frame stays decoded in memory, so keep animations small.

enz_animated_svg plays an SVG's SMIL and CSS animations, drawing and waking only when the picture changes:

rust
use enzui_widgets::animated_svg::{AnimatedSvg, enz_animated_svg};

let svg = AnimatedSvg::parse(&bytes)?;

enz_animated_svg(&svg)
    .width(96)
    .height(96)
    .playing(self.playing)
    .label("Loading")

Both pause when they scroll out of view or the window stops drawing, resume where they left off, pause on request with .playing(false), and show their first frame under reduced motion.

Icons

enz_icon(name) draws a bundled Lucide icon from enzui-icons. An unknown name is logged once under the enzui::icon target. Directional icons named by meaning (navigation.back, navigation.forward, navigation.sidebar_left) point the other way in a right-to-left locale; a literal glyph name such as chevron-right is drawn as asked, and enz_icon_for_direction takes an explicit direction. enz_icon_from_handle and enz_icon_from_image draw your own artwork in the icon slot.

With enzui-services' desktop-icons feature, DesktopIconService looks up the freedesktop icon theme (file-type and folder artwork) on a background worker.

Cropping an avatar

Use image_cropper with a caller-owned crop draft and viewer transform. Keep the committed avatar until export succeeds, and reject completions for stale requests. The export runs through enzui-resources' optional image-ops feature (ImageOperations: crop, encode as PNG, JPEG with an explicit matte, or lossless WebP, and strip metadata). A circular preview does not make the exported image circular.

Loading and decoding

enzui-resources loads remote resources and decodes images:

FeatureWhat it adds
curl-transport (default)HTTP(S) loading through the system libcurl
heifHEIC decoding through a runtime-loaded libheif
local-imagesImages from local files through a provider registry
first-frame-previewsGIF and APNG posters from their first frame
derived-previewsPersistent previews derived from other media
image-opsCrop, encode and strip metadata

HandleCache is a byte-bounded least-recently-used cache of decoded image handles, for thumbnails scrolled back into view. Decode limits refuse oversized images before they are decoded.

Video and audio

enz_video is a video surface plus transport, driven by a media snapshot and a decoded frame. A video source with no frame yet shows a loading skeleton; an audio-only source shows a named notice. enz_media_controls is the transport bar on its own; a music app should use it rather than build one.

The backends live in enzui-services:

  • gstreamer provides audio and video playback services and event sounds (event_sound). Remote streams pass a destination and redirect gate before a decoder connects.
  • mpris exposes playback to the desktop's media keys and controls (playerctl, shell media widgets).
  • pdf-preview and gstreamer together back document_preview: PDF page rendering and video poster frames.

GStreamer needs the plugins for the formats you play at run time (good, bad, libav); see Installation.

Frames from another process

enzui-external-image draws DMA-BUF frames produced by another process on the renderer's own GPU device without a CPU copy. Under the software renderer these show their CPU fallback.

Pen and pointer

Tablets arrive as Event::Stylus on Wayland (zwp_tablet_v2); on X11 the pen arrives as a mouse and pointer lock is not available.