Skip to main content

Module surface

Module surface 

Source
Expand description

Surfaces: typed views over the double-buffered shared buffer a UI plugin paints and the viewer samples.

A Surface<Cells> paints graphemes, colours and attributes per cell; a Surface<Pixels> paints RGBA8 pixels. Both work the same way:

  • Create the surface once, by the id the manifest declares (Surface::<Cells>::new("card")). The SDK asks the host for its layout, allocates the region in the plugin’s memory and attaches it.
  • Draw with the model’s methods and the crate::Shapes helpers. Every write records the rectangle it touched.
  • Surface::commit publishes the painted slot with the merged dirty rectangles, bumps the sequence number, and switches slots. The next slot starts as a copy of what was just committed (copied lazily, and only the rectangles that changed), so drawing is always incremental.
  • On a resize the SDK rebinds every surface of that id to a new region before the plugin sees crate::Event::Resize; the first commit at the new size is fully dirty, and the old region is freed only after it, as the host requires. Nothing is drawn while a surface has no size.

The region layout (a 32-byte header of eight little-endian u32 words seq, model, cols, rows, px-w, px-h, cell-px-w, cell-px-h, then two slots) is the contract in wit/plugin.wit.

Structs§

AnySurface
A surface whose manifest lists both models ("model": ["pixels", "cells"]): the viewer picks one per its capabilities and may switch (graphics arriving or leaving), which the plugin sees as a crate::Event::Resize. AnySurface::get hands out the surface in the model the viewer uses now.
Cell
One cell, read back from the buffer.
CommitInfo
What the last commit published (for tests and diagnostics).
Instances
The instances of a pane.footer or pane.header surface (one per pane the viewer shows, named <surface>@<pane>) or of a machine.after surface (one per machine, <surface>@<machine>). Pass every event to Instances::event; it creates an instance’s surface when the viewer first sizes it and drops it when the viewer removes it (a zero-size resize), and says which pane or machine changed.
Surface
A surface in model M (Cells or Pixels). See the module docs.

Enums§

AnySurfaceMut
AnySurface in the model the viewer uses now.
Cells
The cell model: graphemes, colours and attributes per cell.
Model
A surface’s model, as the manifest declares it.
Pixels
The graphics model: RGBA8 pixels, the surface’s cells times the cell pixel size.

Constants§

CELL_LEN
Bytes per cell in the cell model.
HEADER_LEN
Bytes before slot 0.
PIXEL_LEN
Bytes per pixel in the graphics model.

Traits§

SurfaceModel
The two surface models: Cells and Pixels.

Functions§

instance_pane
The pane an instance id names, when id is an instance of surface.