Struct matrix_display::MatrixDisplay
[−]
[src]
pub struct MatrixDisplay<'a, T> where
T: Clone,
T: ToString + 'a, { /* fields omitted */ }
Stores a matrix of data and offers a way to pretty print it
Example: visualising a 256 colors palette:
use matrix_display::*; let format = Format::new(5,1); let board = (0..256) .map(|x| cell::Cell::new(x, 0, x as u8)) .collect::<Vec<_>>(); let data = matrix::Matrix::new(8, board); let display = MatrixDisplay::new(format, data); display.print(&mut std::io::stdout(), &style::BordersStyle::Thin);
Methods
impl<'a, T> MatrixDisplay<'a, T> where
T: Clone,
T: ToString + 'a,
[src]
T: Clone,
T: ToString + 'a,
fn new(f: &'a Format, m: &'a mut Matrix<Cell<T>>) -> MatrixDisplay<'a, T>
Construct a matrix display
f: the format of a cell (width, height)
m: a reference to the data (&Matrix
fn width(&self) -> usize
The matrix's width in number of characters
fn height(&self) -> usize
The matrix's height in number of characters
fn print<Out: Write>(&self, out: &mut Out, borders: &BordersStyle)
Print a matrix. This is the most important method of this library
Pick a BorderStyle, an output that implements the Write trait and you're good to go!
fn coordinates_at_cursor_position(
&self,
(x, y): (usize, usize)
) -> (usize, usize)
&self,
(x, y): (usize, usize)
) -> (usize, usize)
Takes a cursor position in (usize, usize) and returns the coordinates of the cell under the cursor
fn cell_at_cursor_position(&mut self, cursor: (usize, usize)) -> &mut Cell<T>
Takes a cursor position in characters (x, y) and returns a mutable reference to the corresponding cell
This is used to modify a cell that was clicked