pub struct DrawBuffer { /* private fields */ }Expand description
A fixed-width row of screen cells under construction.
DrawBuffer — a scratch row of Cells.
A view fills a DrawBuffer one display line at a time and then blits it. The
buffer is a Vec<Cell> of an explicit width; writes past the end are clipped
against that width. Text writing delegates to the text primitives, so
width-aware truncation and double-width handling are shared with the rest of
the renderer.
§No 0 = retain sentinel
move_char always writes both the char and the
style. For the rare “change only the attribute / only the char of a cell”
cases, use put_attribute /
put_char.
§Turbo Vision heritage
Ports TDrawBuffer (drawbuf.h, drivers.cpp), which allocated a fixed
capacity sized to the screen; here it is a Vec<Cell> of an explicit width.
The original packed a 0 char/attribute to mean “keep what is already there”;
that sentinel is dropped in favour of the typed cell model (deviation D6).
Text drawing routes through the shared Unicode-aware text primitives
(deviation D13).
Implementations§
Source§impl DrawBuffer
impl DrawBuffer
Sourcepub fn new(width: usize) -> Self
pub fn new(width: usize) -> Self
A blank buffer width columns wide (every cell a space with the default
style). width is the capacity against which all writes are clipped.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
The buffer’s width in columns; all write operations are clipped to this limit.
Equals the width passed to DrawBuffer::new. Use this to cap a fill
count or guard a manual write loop so it stays within the allocated buffer.
Sourcepub fn cells(&self) -> &[Cell]
pub fn cells(&self) -> &[Cell]
A read-only view of all cells in the buffer, from column 0 to
capacity − 1.
Call this after filling the buffer to hand the completed row to a
drawing context (e.g. pass it to ctx.write_buf), or to inspect
individual cells in tests. The slice length always equals capacity.
Sourcepub fn put_char(&mut self, indent: usize, ch: char)
pub fn put_char(&mut self, indent: usize, ch: char)
Set the char of a single cell at indent, leaving its style untouched.
Prefer this over move_char when you only want to
change the glyph of an already-styled cell — for example, placing a border
corner over a cell whose colour was set by an earlier pass. Out-of-range
indent is a silent no-op.
Sourcepub fn put_attribute(&mut self, indent: usize, style: Style)
pub fn put_attribute(&mut self, indent: usize, style: Style)
Set the style of a single cell at indent, leaving its char untouched.
Prefer this over move_char when you only want to
restyle a cell without changing its glyph — for example, applying a
highlight colour to text that was placed by an earlier pass. Out-of-range
indent is a silent no-op.
Sourcepub fn move_char(&mut self, indent: usize, ch: char, style: Style, count: usize)
pub fn move_char(&mut self, indent: usize, ch: char, style: Style, count: usize)
Fill count cells from indent with ch and style, clipped to
capacity. (See the DrawBuffer docs on the dropped 0 = retain sentinel.)
Sourcepub fn move_str_part(
&mut self,
indent: usize,
text: &str,
style: Style,
max_width: usize,
str_indent: usize,
) -> usize
pub fn move_str_part( &mut self, indent: usize, text: &str, style: Style, max_width: usize, str_indent: usize, ) -> usize
Write text at column indent, starting from column str_indent of
text, with a fixed style, writing at most max_width columns. Returns
the number of cells written.
Sourcepub fn move_str(&mut self, indent: usize, text: &str, style: Style) -> usize
pub fn move_str(&mut self, indent: usize, text: &str, style: Style) -> usize
Write text at indent with style, unbounded width, from the start of
text.
Sourcepub fn move_cstr_part(
&mut self,
indent: usize,
text: &str,
lo: Style,
hi: Style,
max_width: usize,
str_indent: usize,
) -> usize
pub fn move_cstr_part( &mut self, indent: usize, text: &str, lo: Style, hi: Style, max_width: usize, str_indent: usize, ) -> usize
Write a control string: text is drawn with lo, and each ~ toggles
between lo and hi (the classic hotkey-highlight markup). Returns the
number of cells written.
Sourcepub fn move_cstr(
&mut self,
indent: usize,
text: &str,
lo: Style,
hi: Style,
) -> usize
pub fn move_cstr( &mut self, indent: usize, text: &str, lo: Style, hi: Style, ) -> usize
Write a control string at full width, from the start.
Sourcepub fn move_buf(&mut self, indent: usize, src: &[Cell])
pub fn move_buf(&mut self, indent: usize, src: &[Cell])
Copy a run of pre-built cells into the buffer at indent, clipped to
capacity.
Use move_buf when you have already assembled the styled cells — for
example, copying another view’s row out of a DrawBuffer or blitting a
pre-rendered sprite. For the common cases of filling with a single
character+style use move_char; for rendering a string
use move_str or move_cstr.
In the typed cell model the meaningful operation is copying cells, so this
takes a &[Cell] rather than a raw byte buffer.
§Turbo Vision heritage
Ports MoveBuf (drivers.cpp); the C++ Word/attribute pair buffer
becomes a typed &[Cell] slice. MoveBuf’s raw-byte
coupling to the TDrawBuffer layout has no equivalent here.
Trait Implementations§
Source§impl Clone for DrawBuffer
impl Clone for DrawBuffer
Source§fn clone(&self) -> DrawBuffer
fn clone(&self) -> DrawBuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DrawBuffer
impl RefUnwindSafe for DrawBuffer
impl Send for DrawBuffer
impl Sync for DrawBuffer
impl Unpin for DrawBuffer
impl UnsafeUnpin for DrawBuffer
impl UnwindSafe for DrawBuffer
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.