pub struct Buffer { /* private fields */ }Expand description
A window of cells, and a record of which shape decided each of them.
Every position in a freshly created buffer is undefined: it holds no cell until stamp is
called for it. The buffer is a temporary working surface, not the document; there is no erase.
The record is kept beside the cells rather than inside one, in a map of its own, for the
reason two cells that render alike must stay one cell: an identity inside a Cell would be a
part of the cell rather than a note about who wrote it, and every equality, every render and
every catalog lookup would then depend on it. owner reads the record back.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn new(window: Window) -> Self
pub fn new(window: Window) -> Self
Creates a buffer with no positions defined, holding window.
A width or height of zero is allowed and gives a buffer with no positions; construction cannot fail.
Sourcepub fn window(&self) -> Window
pub fn window(&self) -> Window
The window this buffer was created with.
A value rather than a borrow: a window is two small Copy values, and a caller that
reads it while holding the buffer needs nothing back. What it is for is the translation an
offset into the window needs and the size a rendering asks for.
Trait Implementations§
Source§impl CellReader for Buffer
impl CellReader for Buffer
Source§impl OwnerReader for Buffer
impl OwnerReader for Buffer
Source§impl StampSink for Buffer
impl StampSink for Buffer
Source§fn stamp(
&mut self,
at: Pos,
cell: Cell,
mode: StampMode,
owner: Option<ShapeId>,
)
fn stamp( &mut self, at: Pos, cell: Cell, mode: StampMode, owner: Option<ShapeId>, )
Writes cell at the absolute position at, under mode.
A position outside the window is left unchanged. Writing an undefined position defines it
entirely, Unset arms included, whichever mode is given. Writing an already-defined
position consults mode for which side decides: StampMode::Above overwrites the base
stroke and reads the stamp’s arms, leaving alone whichever ones cell itself leaves
Unset; StampMode::Below leaves the base stroke alone and reads the target’s arms
instead, writing only the sides the cell already stored has left Unset. A cell holding a
literal glyph or a named symbol is decided on every side either way, so it behaves as the
fully decided case throughout — see A cell can be a literal instead and A cell can name
a symbol instead in docs/model.md.
owner is the identity of whoever is stamping, or None for a stamp by nobody: a figure
this crate draws on its own gallery carries no identity, and neither does a caller with no
diagram to draw from. None records nothing rather than recording an absence — it is
not an owner the buffer holds, so a position keeps whoever holds it and answers None where
nobody does.
What the stamp records follows the rules that decide the cell rather than sitting beside
them, which is what makes the record and the picture one thing instead of two: this stamp
owns the position when it decides at least one side of it, and under StampMode::Below
only when nobody holds it already. A shape behind therefore cannot take a cell from one in
front of it however much it decides there, and since every stamp in front takes, the record
comes out the same whichever order a diagram is drawn in.