[][src]Enum gameboard::cell::Cell

pub enum Cell {
    Empty,
    ResourceId(u16),
    Char(char),
    Content(String),
}

Cell content.

Variants

Empty

Empty cell. It will be filled with spaces.

ResourceId(u16)

Resource id. Content is stored in ResourceTable. If you use this cell type, you must add resource table to board.

Char(char)

Char (Unicode code point). If cell size is more than 1x1, the cell will be filled with this character.

Content(String)

Arbitrary string. String will be written into cell by rows.

You can use escape sequences. Termion provides termion::style and termion::color for this. You don't have to reset style at the end, it'll be done automatically.

Implementation note

If you use Cursor, do not use termion::style::Reset and termion::color::Bg inside string. It will break cursor highlighting, because it uses termion::color::Bg as well and they will overlap.

Examples

use termion::{style, color};

fn create_resources() -> ResourceTable {
    let mut res = ResourceTable::new();
    res.insert(0, String::from("  OO   O  O   OO  "));
    res.insert(1, String::from(" X  X   XX   X  X "));
    res
}

let cursor = Cursor::new(color::Rgb(0, 0, 200), Position(0, 0), true, None);
let mut board = Board::new(3, 3, 6, 3, true, Some(create_resources()));
board.init_from_vec(
    &vec![
        Cell::Empty,
        Cell::ResourceId(0),
        Cell::ResourceId(1),
        Cell::Char('z'),
        Cell::Char('▒'),
        Cell::Content(
            format!("{}aaaaaaaa{}aaaaaaaaaa",
                    color::Fg(color::Red),
                    color::Fg(color::Blue))
        ),
        // this cell breaks cursor highlighting
        Cell::Content(
            format!("{}bbb{}bbbbb{}bbbb{}bbb{}bbb",
                    color::Fg(color::Red),
                    style::Bold,
                    style::Reset,
                    color::Fg(color::Blue),
                    style::Reset)
        ),
        // this cell breaks cursor highlighting
        Cell::Content(
            format!("{}cccccccccccc{}cccccc",
                    color::Bg(color::Red),
                    style::Reset)
        ),
        Cell::Content(
            format!("{}dddddddd{}dddddddddd",
                    color::Fg(color::Red),
                    style::Bold)
        )],
    Some(cursor));

Trait Implementations

impl Clone for Cell[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl Send for Cell

impl Sync for Cell

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]