[−][src]Struct utile_cli::cli::Layer2D
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>
Methods
impl Layer2D
[src]
pub fn new(
posx: i32,
posy: i32,
length: usize,
height: usize,
populator: Layer
) -> Layer2D
[src]
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.
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
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,