Guide API
Skip to main content

DrawBuffer

Struct DrawBuffer 

Source
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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.)

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> DrawBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DrawBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CustomValue for T
where T: Any + Debug,

Source§

fn as_any_rc(self: Rc<T>) -> Rc<dyn Any>

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.