[][src]Struct utile_cli::cli::Layer2D

pub struct Layer2D {
    pub posx: i32,
    pub posy: i32,
    pub length: usize,
    pub height: usize,
    pub layers: Vec<Layer>,
    // some fields omitted
}

An arbitrary type that derives from Layer however can handle both X and Y coordinates. A Layer2D contains an (2D) array of layers allowing them to be rendered in a container and be indexed as such.

Examples

A Layer2D can be initialized using new:

let l = Layer::new(0, 0);
let l2d = Layer2D::new(0, 0, 5, 5, l);

l in this case is the populator which will fill the Layer2D on initialization. l also does not need any positional arguments as they will be overriden on the l2d initialization.

A Layer2D can be populated again using the populate method:

let l2 = Layer::new(0, 0);
l2.set_content("X".into());
l2d.populate(l2);

This results in a 5x5 box of X characters.

Any layer in a Layer2D can be retrieved using index or get:

l2d.index(3, 4); // returns a *mutable* Layer (&mut Layer)
l2d.get(3, 4);   // returns a *immutable* Layer (&Layer)

A layer can be displayed from a terminal using add_layer2d and refresh, much like regular layers:

t.add_layer2d(l2d); // <- returns a &mut Layer2D which can be editted
t.refresh();

Or it can be displayed externally by using draw_layer2d:

t.draw_layer2d(&layer);
t.draw_layer2d_static(&layer); // <- a layer can also be drawn without editting the cursor position

Fields

posx: i32posy: i32length: usizeheight: usizelayers: Vec<Layer>

Methods

impl Layer2D[src]

pub fn new(
    posx: i32,
    posy: i32,
    length: usize,
    height: usize,
    populator: Layer
) -> Layer2D
[src]

Returns a new layer2d at posx, posy with length and height. Position is determined from the top left corner.

pub fn populate(&mut self, populator: Layer)[src]

Populates a layer2d with populator

pub fn index(&mut self, x: usize, y: usize) -> &mut Layer[src]

Returns a mutable reference to the layer at x and y

pub fn get(&self, x: usize, y: usize) -> &Layer[src]

Returns a immutable reference to the layer at x and y

Trait Implementations

impl Clone for Layer2D[src]

impl Debug for Layer2D[src]

Auto Trait Implementations

impl RefUnwindSafe for Layer2D

impl Send for Layer2D

impl Sync for Layer2D

impl Unpin for Layer2D

impl UnwindSafe for Layer2D

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.