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::Shapeshelpers. Every write records the rectangle it touched. Surface::commitpublishes 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 acrate::Event::Resize.AnySurface::gethands out the surface in the model the viewer uses now. - Cell
- One cell, read back from the buffer.
- Commit
Info - What the last commit published (for tests and diagnostics).
- Instances
- The instances of a
pane.footerorpane.headersurface (one per pane the viewer shows, named<surface>@<pane>) or of amachine.aftersurface (one per machine,<surface>@<machine>). Pass every event toInstances::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(CellsorPixels). See the module docs.
Enums§
- AnySurface
Mut AnySurfacein 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§
- Surface
Model - The two surface models:
CellsandPixels.
Functions§
- instance_
pane - The pane an instance id names, when
idis an instance ofsurface.