Struct tui::buffer::Buffer
[−]
[src]
pub struct Buffer { pub area: Rect, pub content: Vec<Cell>, }
A buffer that maps to the desired content of the terminal after the draw call
No widget in the library interacts directly with the terminal. Instead each of them is required to draw their state to an intermediate buffer. It is basically a grid where each cell contains a grapheme, a foreground color and a background color. This grid will then be used to output the appropriate escape sequences and characters to draw the UI as the user has defined it.
Examples:
use tui::buffer::{Buffer, Cell}; use tui::layout::Rect; use tui::style::{Color, Style, Modifier}; let mut buf = Buffer::empty(Rect{x: 0, y: 0, width: 10, height: 5}); buf.get_mut(0, 2).set_symbol("x"); assert_eq!(buf.get(0, 2).symbol, "x"); buf.set_string(3, 0, "string", &Style::default().fg(Color::Red).bg(Color::White)); assert_eq!(buf.get(5, 0), &Cell{ symbol: String::from("r"), style: Style { fg: Color::Red, bg: Color::White, modifier: Modifier::Reset }}); buf.get_mut(5, 0).set_char('x'); assert_eq!(buf.get(5, 0).symbol, "x");
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
Methods
impl Buffer
[src]
fn empty(area: Rect) -> Buffer
Returns a Buffer with all cells set to the default one
fn filled(area: Rect, cell: Cell) -> Buffer
Returns a Buffer with all cells initialized with the attributes of the given Cell
fn content(&self) -> &[Cell]
Returns the content of the buffer as a slice
fn area(&self) -> &Rect
Returns the area covered by this buffer
fn get(&self, x: u16, y: u16) -> &Cell
Returns a reference to Cell at the given coordinates
fn get_mut(&mut self, x: u16, y: u16) -> &mut Cell
Returns a mutable reference to Cell at the given coordinates
fn index_of(&self, x: u16, y: u16) -> usize
Returns the index in the Vec
fn pos_of(&self, i: usize) -> (u16, u16)
Returns the coordinates of a cell given its index
fn set_string(&mut self, x: u16, y: u16, string: &str, style: &Style)
Print a string, starting at the position (x, y)
fn set_stringn(&mut self,
x: u16,
y: u16,
string: &str,
limit: usize,
style: &Style)
x: u16,
y: u16,
string: &str,
limit: usize,
style: &Style)
Print at most the first n characters of a string if enough space is available until the end of the line
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
fn reset(&mut self)
Reset all cells in the buffer
fn merge(&mut self, other: Buffer)
Merge an other buffer into this one
Trait Implementations
impl Debug for Buffer
[src]
impl Clone for Buffer
[src]
fn clone(&self) -> Buffer
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more