pub struct Buffer {
pub area: Rect,
pub content: Vec<Cell>,
}Fields§
§area: RectThe 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
impl Buffer
sourcepub fn filled(area: Rect, cell: Cell) -> Self
pub fn filled(area: Rect, cell: Cell) -> Self
Returns a Buffer with all cells initialized with the attributes of the given Cell
sourcepub fn get(&self, x: u16, y: u16) -> &Cell
pub fn get(&self, x: u16, y: u16) -> &Cell
Returns a reference to Cell at the given coordinates
sourcepub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell
pub fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell
Returns a mutable reference to Cell at the given coordinates
sourcepub fn index_of(&self, x: u16, y: u16) -> usize
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.
sourcepub fn pos_of(&self, i: usize) -> (u16, u16)
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.
sourcepub fn set_string<T, S>(&mut self, x: u16, y: u16, string: T, style: S)
pub fn set_string<T, S>(&mut self, x: u16, y: u16, string: T, style: S)
Print a string, starting at the position (x, y)
sourcepub fn set_stringn<T, S>(
&mut self,
x: u16,
y: u16,
string: T,
max_width: usize,
style: S,
) -> (u16, u16)
pub fn set_stringn<T, S>( &mut self, x: u16, y: u16, string: T, max_width: usize, style: S, ) -> (u16, u16)
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.
sourcepub fn set_style<S: Into<Style>>(&mut self, area: Rect, style: S)
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>).
sourcepub fn resize(&mut self, area: Rect)
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
sourcepub fn diff<'a>(&self, other: &'a Self) -> Vec<(u16, u16, &'a Cell)>
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 Debug for Buffer
impl Debug for Buffer
source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
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 asRect { x: 1, y: 2, width: 3, height: 4 }content: displayed as a list of strings representing the content of the bufferstyles: 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.
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 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,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)