Skip to main content

Layer

Struct Layer 

Source
pub struct Layer {
    pub posx: i32,
    pub posy: i32,
    pub inner_content: String,
    /* private fields */
}
Expand description

An arbitrary type that contains a position and content. A layer can be positioned anywhere in the console, and it can instead be edited as a string without manual manipulation of the cursor.

A layer is one dimensional, meaning that it does not fit multiple lines.

Layers may shrink and grow, however have allocated space in the terminal, for example, a layer with content “Hello” which then is changed to “Bye” will actually appear on the console as “Bye “ (with two spaces). This means that they have their own space depending on their longest length string. This trait is useful for hiding certain objects from view, however can be reset using shrink which removes trailing whitespace.

§Examples

A layer can be initialized using new:

let layer = Layer::new(0, 0);
layer.set_content("Hello world!".into());

A layer can then be displayed from a terminal either by being added using add_layer and then displayed using refresh:

let new: &mut Layer = t.add_layer(layer);
t.refresh();

Or it can be displayed externally by using draw_layer:

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

A layer also contains another type of content called inner_content which will never be displayed to the terminal, however may contain useful data about the layer:

layer.inner_content = "Hello rust!".into();
layer.inner_to_outer(); // <- replaces the outer content with the inner content.

Fields§

§posx: i32§posy: i32§inner_content: String

Implementations§

Source§

impl Layer

Source

pub fn new(posx: i32, posy: i32) -> Layer

Returns a new layer at posx, posy

Source

pub fn get_content(&self) -> String

Returns a clone of the outer content of the layer.

Source

pub fn set_content(&mut self, c: String) -> &mut Layer

Sets the current outer content of the layer.

Source

pub fn inner_to_outer(&mut self)

Replaces the outer content with the inner content.

Source

pub fn shrink(&mut self)

Removes any hiding content.

Trait Implementations§

Source§

impl Clone for Layer

Source§

fn clone(&self) -> Layer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Layer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Layer

§

impl RefUnwindSafe for Layer

§

impl Send for Layer

§

impl Sync for Layer

§

impl Unpin for Layer

§

impl UnsafeUnpin for Layer

§

impl UnwindSafe for Layer

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.