Trait CellAccessor

Source
pub trait CellAccessor: HasSize {
    // Required methods
    fn cellvec(&self) -> &Vec<Cell>;
    fn cellvec_mut(&mut self) -> &mut Vec<Cell>;

    // Provided methods
    fn clear(&mut self, blank: Cell) { ... }
    fn pos_to_index(&self, x: usize, y: usize) -> Option<usize> { ... }
    fn get(&self, x: usize, y: usize) -> Option<&Cell> { ... }
    fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut Cell> { ... }
}

Required Methods§

Source

fn cellvec(&self) -> &Vec<Cell>

Source

fn cellvec_mut(&mut self) -> &mut Vec<Cell>

Provided Methods§

Source

fn clear(&mut self, blank: Cell)

Clears self, using the given Cell as a blank.

Source

fn pos_to_index(&self, x: usize, y: usize) -> Option<usize>

Source

fn get(&self, x: usize, y: usize) -> Option<&Cell>

Returns a reference to the Cell at the given coordinates, or None if the index is out of bounds.

§Examples
use rustty::{Terminal, CellAccessor};

let mut term = Terminal::new().unwrap();

let a_cell = term.get(5, 5);
Source

fn get_mut(&mut self, x: usize, y: usize) -> Option<&mut Cell>

Returns a mutable reference to the Cell at the given coordinates, or None if the index is out of bounds.

§Examples
use rustty::{Terminal, CellAccessor};

let mut term = Terminal::new().unwrap();

let a_mut_cell = term.get_mut(5, 5);
Examples found in repository?
examples/circle.rs (line 57)
26fn main() {
27    // Create our terminal, dialog window and main canvas
28    let mut term = Terminal::new().unwrap();
29    let mut optiondlg = create_optiondlg();
30    let mut canvas = Widget::new(term.size().0, term.size().1 - 4);
31
32    // Align canvas to top left, and dialog to bottom right
33    optiondlg.window_mut().align(&term, HorizontalAlign::Right, VerticalAlign::Bottom, 0);
34    canvas.align(&term, HorizontalAlign::Left, VerticalAlign::Top, 0);
35
36    let mut radius = 10u32;
37    'main: loop {
38        while let Some(Event::Key(ch)) = term.get_event(Duration::new(0, 0)).unwrap() {
39            match ch {
40                'q' => break 'main,
41                '+' => radius = radius.saturating_add(1),
42                '-' => radius = radius.saturating_sub(1),
43                _ => {}
44            }
45        }
46        // Grab the size of the canvas
47        let (cols, rows) = canvas.size();
48        let (cols, rows) = (cols as isize, rows as isize);
49
50        let (a, b) = (cols / 2, rows / 2);
51
52        // Main render loop, draws the circle to canvas
53        for i in 0..cols * rows {
54            let y = i as isize / cols;
55            let x = i as isize % cols;
56
57            let mut cell = canvas.get_mut(x as usize, y as usize).unwrap();
58
59            if ((x - a).pow(2) / 4 + (y - b).pow(2)) <= radius.pow(2) as isize {
60                cell.set_ch(BLOCK);
61            } else {
62                cell.set_ch(' ');
63            }
64        }
65
66        // draw the canvas, dialog window and swap buffers
67        canvas.draw_into(&mut term);
68        optiondlg.window().draw_into(&mut term);
69        term.swap_buffers().unwrap();
70    }
71}

Implementors§