zgui

Images and drawing

Choose between decoded images, declarative vectors, imperative canvases, GPU surfaces, custom elements, and shader effects.

zgui has four elements for visual content. Pick one by what you have to draw:

ElementInputUse it for
imagePNG, JPEG, WebP, or GIF bytesPhotographs and raster assets
vectorPath notation or an SVG documentIcons, logos, and other static vector art
canvasShapes and data series that Rust code buildsCharts, plots, editors, and generated drawings
surfaceA wgpu texture from another rendererGames, video, and other GPU subsystems

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

image and surface can give layout a natural size or aspect ratio. vector and canvas have no natural size and draw into whatever box CSS gives them. An unstyled canvas is 300 by 150 CSS pixels; an unstyled vector can have zero area.

When none of these fits:

  • A custom element is one retained widget that measures its own children and paints quads, paths, and glyph runs.
  • A custom shader fills, shapes, or filters a box with your own WGSL.

Performance

  • An image is decoded once, at the size it is displayed, and drawn from a texture.
  • A surface stays in its own texture and is composited as one quad.
  • vector, canvas, and custom-element paths share the vector renderer. Simple and repeated shapes are rasterised once or not at all, and other paths keep their GPU work while the geometry is unchanged. Keep drawings fast has the rules.

On this page