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

The area represented by this buffer

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

Methods

impl Buffer
[src]

[src]

Returns a Buffer with all cells set to the default one

[src]

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

[src]

Returns the content of the buffer as a slice

[src]

Returns the area covered by this buffer

[src]

Returns a reference to Cell at the given coordinates

[src]

Returns a mutable reference to Cell at the given coordinates

[src]

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

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

Examples

let rect = Rect::new(200, 100, 10, 10);
let buffer = Buffer::empty(rect);
// Global coordinates to the top corner of this buffer's area
assert_eq!(buffer.index_of(200, 100), 0);

Panics

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

let rect = Rect::new(200, 100, 10, 10);
let buffer = Buffer::empty(rect);
// Top coordinate is outside of the buffer in global coordinate space, as the Buffer's area
// starts at (200, 100).
buffer.index_of(0, 0); // Panics

[src]

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

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

Examples

let rect = Rect::new(200, 100, 10, 10);
let buffer = Buffer::empty(rect);
assert_eq!(buffer.pos_of(0), (200, 100));
assert_eq!(buffer.pos_of(14), (204, 101));

Panics

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

let rect = Rect::new(0, 0, 10, 10); // 100 cells in total
let buffer = Buffer::empty(rect);
// Index 100 is the 101th cell, which lies outside of the area of this Buffer.
buffer.pos_of(100); // Panics

[src]

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

[src]

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

[src]

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

[src]

Reset all cells in the buffer

[src]

Merge an other buffer into this one

Trait Implementations

impl Debug for Buffer
[src]

[src]

Formats the value using the given formatter. Read more

impl Clone for Buffer
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Default for Buffer
[src]

[src]

Returns the "default value" for a type. Read more

Auto Trait Implementations

impl Send for Buffer

impl Sync for Buffer