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
impl Layer2D
Sourcepub fn new(
posx: i32,
posy: i32,
length: usize,
height: usize,
populator: Layer,
) -> Layer2D
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.