[][src]Struct gameboard::cursor::Cursor

pub struct Cursor { /* fields omitted */ }

Cursor structure.

Methods

impl Cursor[src]

pub fn new(
    background: Rgb,
    position: Position,
    wrap_around: bool,
    get_direction: Option<fn(key: Key) -> Option<Direction>>
) -> Self
[src]

Creates new cursor.

Arguments

background - background color of the cell where cursor is placed. Use termion::color.

position - cursor start position.

wrap_around - should cursor be wrapped around or not.

get_direction - pointer to key handler function (optional). This function should translate key into cursor move direction. Function must return None if key is not handled. If function isn't provided the default function is used.

fn get_direction_default(key: Key) -> Option<Direction> {
    match key {
        Key::Char('a') | Key::Left => Some(Direction::Left),
        Key::Char('s') | Key::Down => Some(Direction::Down),
        Key::Char('w') | Key::Up => Some(Direction::Up),
        Key::Char('d') | Key::Right => Some(Direction::Right),
        _ => None,
    }
}

Examples

use termion::color;

const START_POSITION: Position = Position(1, 1);
let cursor = Cursor::new(color::Rgb(0, 0, 200), START_POSITION, true, None);

Auto Trait Implementations

impl Send for Cursor

impl Sync for Cursor

Blanket Implementations

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

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]