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 positionA 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: StringImplementations§
Source§impl Layer
impl Layer
Sourcepub fn get_content(&self) -> String
pub fn get_content(&self) -> String
Returns a clone of the outer content of the layer.
Sourcepub fn set_content(&mut self, c: String) -> &mut Layer
pub fn set_content(&mut self, c: String) -> &mut Layer
Sets the current outer content of the layer.
Sourcepub fn inner_to_outer(&mut self)
pub fn inner_to_outer(&mut self)
Replaces the outer content with the inner content.