zgui

Media and drawing

Choose between decoded images, declarative vectors, imperative canvases, and external GPU surfaces.

zgui has four elements for visual content. They use different input and rendering paths.

ElementInputUse it for
imagePNG, JPEG, WebP, or GIF bytesPhotographs and raster assets
vectorPath notation or an SVG documentStatic or declarative vector art
canvasA retained list of paths that Rust code mutatesCharts, editors, and generated vector art
surfaceA wgpu texture from another rendererGames, video, and GPU subsystems

All four are ordinary elements. CSS sets their box, border, clipping, opacity, transform, and paint order. The content is not a child subtree.

image and surface are replaced elements. Their content can report a natural size or aspect ratio to layout. vector and canvas use the size that CSS gives them. An unstyled canvas is 300 by 150 CSS pixels. An unstyled vector can have zero area.

Choose the least expensive input that expresses the result:

  • Use image when the source is encoded raster data.
  • Use vector when the view can declare the drawing.
  • Use canvas when Rust code must generate or mutate shapes.
  • Use a surface when another renderer already produces a texture.
  • Build a custom element when one retained widget must measure children and emit zgui render primitives.

vector, canvas, and custom paths share the vector pipeline. A small solid path can use a cached coverage mask in the monochrome atlas. Other paths use the general vector rasterizer. An image uses the colour atlas. A surface stays in its own texture and is composited as an external quad.