Struct Layer2D

Source
pub struct Layer2D {
    pub posx: i32,
    pub posy: i32,
    pub length: usize,
    pub height: usize,
    pub layers: Vec<Layer>,
    /* private fields */
}
Expand description

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: i32§posy: i32§length: usize§height: usize§layers: Vec<Layer>

Implementations§

Source§

impl Layer2D

Source

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

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

Source

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

Populates a layer2d with populator

Source

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

Returns a mutable reference to the layer at x and y

Source

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

Returns a immutable reference to the layer at x and y

Trait Implementations§

Source§

impl Clone for Layer2D

Source§

fn clone(&self) -> Layer2D

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Layer2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.