pub struct Buffer { /* private fields */ }Expand description
In-memory screen grid; the render target for one complete frame.
Render back-buffer and cell diff.
Buffer is the in-memory screen grid: the whole view tree is painted into
it each frame, then Buffer::diff compares it against the previous frame so
only changed cells are flushed to the terminal.
The diff algorithm is adapted from ratatui’s Buffer::diff (MIT). Our Cell
(see cell.rs) already encodes double-width glyphs with explicit
wide/trail flags, so the wide-char skipping is driven off those rather
than off unicode-width. ratatui’s skip field is dropped — tvision-rs repaints
the whole tree, so there is nothing to opt out of.
Call Buffer::new to create a blank grid sized to the terminal, paint the
full view tree into it via the renderer, then call Buffer::diff against
the previous frame’s buffer to obtain only the changed cells to flush to the
terminal. The Program root owns two buffers (current and previous) and
swaps them each iteration of the event loop.
Unlike ratatui, Buffer stores only width × height rather than an
area: Rect, because the back buffer is always screen-origin ((0, 0) to
(width-1, height-1)). There is no offset to carry.
§Turbo Vision heritage
Replaces Turbo Vision’s per-view incremental screen writes with a double-buffered whole-tree repaint plus cell diff (deviation D8). The grid and diff are adapted from ratatui rather than ported from the original.
Replaces TVideoBuf (a fixed 80×25 word array of char+attr cells) and
the per-view incremental writeView calls. The dynamic-size grid and
double-buffered whole-tree repaint follow magiblot/tvision’s modernised
screen model rather than the original fixed-buffer approach.
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
A new buffer filled with Cell::default() (a blank space, default style).
Sourcepub fn filled(width: u16, height: u16, cell: Cell) -> Self
pub fn filled(width: u16, height: u16, cell: Cell) -> Self
A new buffer where every cell is a clone of cell.
Sourcepub fn index_of(&self, x: u16, y: u16) -> usize
pub fn index_of(&self, x: u16, y: u16) -> usize
Convert (x, y) to a linear index into content.
Panics in debug builds if x >= width or y >= height.
Sourcepub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell
pub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell
Return a mutable reference to the cell at (x, y).
Sourcepub fn cells(&self) -> &[Cell]
pub fn cells(&self) -> &[Cell]
A slice over all cells in row-major order (for tests / snapshots).
Sourcepub fn row(&self, y: u16) -> &[Cell]
pub fn row(&self, y: u16) -> &[Cell]
A shared slice over row y (width cells), for width-aware row writes.
Panics in debug builds if y >= height.
Sourcepub fn row_mut(&mut self, y: u16) -> &mut [Cell]
pub fn row_mut(&mut self, y: u16) -> &mut [Cell]
A mutable slice over row y (width cells), for width-aware row writes
(e.g. feeding text::draw_str a clipped sub-slice).
Panics in debug builds if y >= height.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset every cell to Cell::default().
Sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resize the buffer to width × height, resetting all content to
Cell::default().
Sourcepub fn diff<'a>(&self, other: &'a Buffer) -> Vec<(u16, u16, &'a Cell)>
pub fn diff<'a>(&self, other: &'a Buffer) -> Vec<(u16, u16, &'a Cell)>
Compare self (the previous/front buffer) against other (the
next/back buffer) and return the cells in other that differ.
Each entry is (x, y, &cell) pointing into other.
Both buffers must have the same dimensions. The invariant is asserted in debug builds; in release the comparison is limited to the overlapping index range.
The algorithm is adapted from ratatui’s Buffer::diff: it iterates the
flat cell array, suppressing the trail cell of a wide glyph via
to_skip, and using invalidated to force repainting the cell that
follows a cell whose previous width was greater than its current
width (e.g. a wide glyph replaced by a narrow one — the trail cell must
be repainted even if it happens to be equal to the old trail cell).
Trait Implementations§
impl Eq for Buffer
impl StructuralPartialEq for Buffer
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnsafeUnpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.