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
impl Format
Sourcepub fn new(w: usize, h: usize) -> Format
pub fn new(w: usize, h: usize) -> Format
Examples found in repository?
More 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§
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> 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
Mutably borrows from an owned value. Read more