Struct cursive_core::views::StackView
source · pub struct StackView { /* private fields */ }
Expand description
Simple stack of views. Only the top-most view is active and can receive input.
Implementations§
source§impl StackView
impl StackView
sourcepub fn fits(&self, position: LayerPosition) -> bool
pub fn fits(&self, position: LayerPosition) -> bool
Returns true
if position
points to a valid layer.
Returns false
if it exceeds the bounds.
sourcepub fn add_fullscreen_layer<T>(&mut self, view: T)where
T: IntoBoxedView,
pub fn add_fullscreen_layer<T>(&mut self, view: T)where
T: IntoBoxedView,
Adds a new full-screen layer on top of the stack.
Fullscreen layers have no shadow.
sourcepub fn add_layer<T>(&mut self, view: T)where
T: IntoBoxedView,
pub fn add_layer<T>(&mut self, view: T)where
T: IntoBoxedView,
Adds new view on top of the stack in the center of the screen.
sourcepub fn layer<T>(self, view: T) -> Selfwhere
T: IntoBoxedView,
pub fn layer<T>(self, view: T) -> Selfwhere
T: IntoBoxedView,
Adds new view on top of the stack in the center of the screen.
Chainable variant.
sourcepub fn get(&self, pos: LayerPosition) -> Option<&dyn View>
pub fn get(&self, pos: LayerPosition) -> Option<&dyn View>
Returns a reference to the layer at the given position.
sourcepub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut dyn View>
pub fn get_mut(&mut self, pos: LayerPosition) -> Option<&mut dyn View>
Returns a mutable reference to the layer at the given position.
sourcepub fn find_layer_from_name(&mut self, id: &str) -> Option<LayerPosition>
pub fn find_layer_from_name(&mut self, id: &str) -> Option<LayerPosition>
Looks for the layer containing a view with the given name.
Returns Some(pos)
if self.get(pos)
has the given name,
or is a parent of a view with this name.
Returns None
if the given name is not found.
Note that the returned position may be invalidated if some layers are removed from the view.
Examples
let mut stack = StackView::new();
stack.add_layer(TextView::new("Back"));
stack.add_layer(Dialog::around(TextView::new("Middle").with_name("text")));
stack.add_layer(TextView::new("Front"));
assert_eq!(stack.find_layer_from_name("text"), Some(LayerPosition::FromBack(1)));
sourcepub fn fullscreen_layer<T>(self, view: T) -> Selfwhere
T: IntoBoxedView,
pub fn fullscreen_layer<T>(self, view: T) -> Selfwhere
T: IntoBoxedView,
Adds a new full-screen layer on top of the stack.
Chainable variant.
sourcepub fn transparent_layer<T>(self, view: T) -> Selfwhere
T: IntoBoxedView,
pub fn transparent_layer<T>(self, view: T) -> Selfwhere
T: IntoBoxedView,
Adds a new transparent layer on top of the stack.
Chainable variant.
sourcepub fn add_layer_at<T>(&mut self, position: Position, view: T)where
T: IntoBoxedView,
pub fn add_layer_at<T>(&mut self, position: Position, view: T)where
T: IntoBoxedView,
Adds a view on top of the stack.
sourcepub fn add_transparent_layer<T>(&mut self, view: T)where
T: IntoBoxedView,
pub fn add_transparent_layer<T>(&mut self, view: T)where
T: IntoBoxedView,
Adds a transparent view on top of the stack in the center of the screen.
sourcepub fn add_transparent_layer_at<T>(&mut self, position: Position, view: T)where
T: IntoBoxedView,
pub fn add_transparent_layer_at<T>(&mut self, position: Position, view: T)where
T: IntoBoxedView,
Adds a transparent view on top of the stack.
sourcepub fn layer_at<T>(self, position: Position, view: T) -> Selfwhere
T: IntoBoxedView,
pub fn layer_at<T>(self, position: Position, view: T) -> Selfwhere
T: IntoBoxedView,
Adds a view on top of the stack at the given position.
Chainable variant.
sourcepub fn remove_layer(&mut self, position: LayerPosition) -> Box<dyn View>
pub fn remove_layer(&mut self, position: LayerPosition) -> Box<dyn View>
sourcepub fn layer_offset(&self, pos: LayerPosition) -> Option<Vec2>
pub fn layer_offset(&self, pos: LayerPosition) -> Option<Vec2>
Computes the offset of the selected view.
sourcepub fn offset(&self) -> Vec2
👎Deprecated since 0.17.0: Use StackView::layer_offset instead.
pub fn offset(&self) -> Vec2
Computes the offset of the current top view.
sourcepub fn layer_sizes(&self) -> Vec<Vec2>
pub fn layer_sizes(&self) -> Vec<Vec2>
Returns the size for each layer in this view.
sourcepub fn move_layer(&mut self, from: LayerPosition, to: LayerPosition)
pub fn move_layer(&mut self, from: LayerPosition, to: LayerPosition)
Moves a layer to a new position in the stack.
This only affects the elevation of a layer (whether it is drawn over or under other views).
Panics
If either from
or to
is out of bounds.