Struct Buffer

Source
pub struct Buffer {
    pub area: Rect,
    pub content: Vec<Cell>,
}

Fields§

§area: Rect

The area represented by this buffer

§content: Vec<Cell>

The content of the buffer. The length of this Vec should always be equal to area.width * area.height

Implementations§

Source§

impl Buffer

Source

pub fn empty(area: Rect) -> Self

Returns a Buffer with all cells set to the default one

Source

pub fn filled(area: Rect, cell: Cell) -> Self

Returns a Buffer with all cells initialized with the attributes of the given Cell

Source

pub fn content(&self) -> &[Cell]

Returns the content of the buffer as a slice

Source

pub const fn area(&self) -> &Rect

Returns the area covered by this buffer

Source

pub fn get(&self, x: u16, y: u16) -> &Cell

Returns a reference to Cell at the given coordinates

Source

pub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell

Returns a mutable reference to Cell at the given coordinates

Source

pub fn index_of(&self, x: u16, y: u16) -> usize

Returns the index in the Vec<Cell> for the given global (x, y) coordinates.

Global coordinates are offset by the Buffer’s area offset (x/y).

§Panics

Panics when given an coordinate that is outside of this Buffer’s area.

Source

pub fn pos_of(&self, i: usize) -> (u16, u16)

Returns the (global) coordinates of a cell given its index

Global coordinates are offset by the Buffer’s area offset (x/y).

§Panics

Panics when given an index that is outside the Buffer’s content.

Source

pub fn set_string<T, S>(&mut self, x: u16, y: u16, string: T, style: S)
where T: AsRef<str>, S: Into<Style>,

Print a string, starting at the position (x, y)

Source

pub fn set_stringn<T, S>( &mut self, x: u16, y: u16, string: T, max_width: usize, style: S, ) -> (u16, u16)
where T: AsRef<str>, S: Into<Style>,

Print at most the first n characters of a string if enough space is available until the end of the line.

Use Buffer::set_string when the maximum amount of characters can be printed.

Source

pub fn set_style<S: Into<Style>>(&mut self, area: Rect, style: S)

Set the style of all cells in the given area.

style accepts any type that is convertible to Style (e.g. Style, Color, or your own type that implements Into<Style>).

Source

pub fn resize(&mut self, area: Rect)

Resize the buffer so that the mapped area matches the given area and that the buffer length is equal to area.width * area.height

Source

pub fn reset(&mut self)

Reset all cells in the buffer

Source

pub fn merge(&mut self, other: &Self)

Merge an other buffer into this one

Source

pub fn diff<'a>(&self, other: &'a Self) -> Vec<(u16, u16, &'a Cell)>

Builds a minimal sequence of coordinates and Cells necessary to update the UI from self to other.

We’re assuming that buffers are well-formed, that is no double-width cell is followed by a non-blank cell.

§Multi-width characters handling:
(Index:) `01`
Prev:    `コ`
Next:    `aa`
Updates: `0: a, 1: a'
(Index:) `01`
Prev:    `a `
Next:    `コ`
Updates: `0: コ` (double width symbol at index 0 - skip index 1)
(Index:) `012`
Prev:    `aaa`
Next:    `aコ`
Updates: `0: a, 1: コ` (double width symbol at index 1 - skip index 2)

Trait Implementations§

Source§

impl Clone for Buffer

Source§

fn clone(&self) -> Buffer

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Buffer

Source§

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

Writes a debug representation of the buffer to the given formatter.

The format is like a pretty printed struct, with the following fields:

  • area: displayed as Rect { x: 1, y: 2, width: 3, height: 4 }
  • content: displayed as a list of strings representing the content of the buffer
  • styles: displayed as a list of: { x: 1, y: 2, fg: Color::Red, bg: Color::Blue, modifier: Modifier::BOLD } only showing a value when there is a change in style.
Source§

impl Default for Buffer

Source§

fn default() -> Buffer

Returns the “default value” for a type. Read more
Source§

impl Hash for Buffer

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Buffer

Source§

fn eq(&self, other: &Buffer) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Buffer

Source§

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 UnwindSafe for Buffer

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