Struct Format

Source
pub struct Format {
    pub cell_w: usize,
    pub cell_h: usize,
}
Expand description

Format of a cell in a matrix

Decide of the cell width and the cell height. The matrix will pad its cells according to a Format.

Example: let format = matrix_display::Format::new(7,3)

Fields§

§cell_w: usize§cell_h: usize

Implementations§

Source§

impl Format

Source

pub fn new(w: usize, h: usize) -> Format

Examples found in repository?
examples/palette.rs (line 5)
4fn main() {
5    let format = Format::new(5, 1);
6    let board = (0..256)
7        .map(|x| cell::Cell::new(x, 0, x as u8))
8        .collect::<Vec<_>>();
9    let mut data = matrix::Matrix::new(8, board);
10    let display = MatrixDisplay::new(&format, &mut data);
11    display.print(&mut std::io::stdout(), &style::BordersStyle::Light);
12}
More examples
Hide additional examples
examples/2048.rs (line 5)
4fn main() {
5    let format = Format::new(7, 3);
6    let colour_theme = vec![
7        247, 78, 222, 220, 214, 208, 202, 196, 162, 160, 126, 90, 88, 54, 53, 52,
8    ];
9    let board = (0..16)
10        .map(|x| {
11            cell::Cell::new(
12                2_f64.powi(x + 1),
13                7,
14                *colour_theme.get(x as usize).unwrap() as u8,
15            )
16        })
17        .collect::<Vec<_>>();
18    let mut data = matrix::Matrix::new(4, board);
19    let display = MatrixDisplay::new(&format, &mut data);
20    display.print(&mut std::io::stdout(), &style::BordersStyle::Heavy);
21}
examples/chess.rs (line 5)
4fn main() {
5    let format = Format::new(7, 3);
6    #[cfg_attr(rustfmt, rustfmt_skip)]
7    let board = vec!['♜', '♞', '♝', '♛', '♚', '♝', '♞', '♜',
8	                 '♟', '♟', '♟', '♟', '♟', '♟', '♟', '♟',
9					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
10                     ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
11					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
12					 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
13					 '♖', '♘', '♗', '♕', '♔', '♗', '♘', '♖',
14					 '♙', '♙', '♙', '♙', '♙', '♙', '♙', '♙']
15        .iter()
16        .enumerate()
17        .map(|(i, x)| {
18            let ansi_fg = 33;
19            let mut ansi_bg = 0;
20            if i % 2 + (i / 8) % 2 == 1 {
21                ansi_bg = 7;
22            }
23            cell::Cell::new(x.clone(), ansi_fg, ansi_bg)
24        })
25        .collect::<Vec<_>>();
26    let mut data = matrix::Matrix::new(8, board);
27    let mut display = MatrixDisplay::new(&format, &mut data);
28    display.cell_at_cursor_position((13, 6)).color.bg = 10;
29    display.print(&mut std::io::stdout(), &style::BordersStyle::None);
30}

Trait Implementations§

Source§

impl Default for Format

Source§

fn default() -> Format

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

Auto Trait Implementations§

§

impl Freeze for Format

§

impl RefUnwindSafe for Format

§

impl Send for Format

§

impl Sync for Format

§

impl Unpin for Format

§

impl UnwindSafe for Format

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