Struct cursive_core::views::FixedLayout
source · pub struct FixedLayout { /* private fields */ }
Expand description
Arranges its children in a fixed layout.
Usually meant to use an external layout engine.
Examples
use cursive_core::{
views::{Button, FixedLayout, TextView},
Rect,
};
let layout = FixedLayout::new()
.child(Rect::from_size((0, 0), (1, 1)), TextView::new("/"))
.child(Rect::from_size((14, 0), (1, 1)), TextView::new(r"\"))
.child(Rect::from_size((0, 2), (1, 1)), TextView::new(r"\"))
.child(Rect::from_size((14, 2), (1, 1)), TextView::new("/"))
.child(
Rect::from_size((3, 1), (11, 1)),
Button::new("Clickme", |s| s.quit()),
);
Implementations§
source§impl FixedLayout
impl FixedLayout
sourcepub fn child<V: IntoBoxedView>(self, position: Rect, view: V) -> Self
pub fn child<V: IntoBoxedView>(self, position: Rect, view: V) -> Self
Adds a child. Chainable variant.
sourcepub fn add_child<V: IntoBoxedView>(&mut self, position: Rect, view: V)
pub fn add_child<V: IntoBoxedView>(&mut self, position: Rect, view: V)
Adds a child.
sourcepub fn get_focus_index(&self) -> usize
pub fn get_focus_index(&self) -> usize
Returns index of focused inner view
sourcepub fn set_focus_index(
&mut self,
index: usize
) -> Result<EventResult, ViewNotFound>
pub fn set_focus_index(
&mut self,
index: usize
) -> Result<EventResult, ViewNotFound>
Attemps to set the focus on the given child.
Returns Err(())
if index >= self.len()
, or if the view at the
given index does not accept focus.
sourcepub fn get_child_mut(&mut self, i: usize) -> Option<&mut dyn View>
pub fn get_child_mut(&mut self, i: usize) -> Option<&mut dyn View>
Returns a mutable reference to a child.
sourcepub fn set_child_position(&mut self, i: usize, position: Rect)
pub fn set_child_position(&mut self, i: usize, position: Rect)
Sets the position for the given child.
sourcepub fn remove_child(&mut self, i: usize) -> Option<Box<dyn View>>
pub fn remove_child(&mut self, i: usize) -> Option<Box<dyn View>>
Removes a child.
If i
is within bounds, the removed child will be returned.
sourcepub fn find_child_from_name(&mut self, name: &str) -> Option<usize>
pub fn find_child_from_name(&mut self, name: &str) -> Option<usize>
Looks for the child containing a view with the given name.
Returns Some(i)
if self.get_child(i)
has the given name, or
contains a view with the given name.
Returns None
if the given name was not found.
Trait Implementations§
source§impl Default for FixedLayout
impl Default for FixedLayout
source§impl View for FixedLayout
impl View for FixedLayout
source§fn draw(&self, printer: &Printer<'_, '_>)
fn draw(&self, printer: &Printer<'_, '_>)
Draws the view with the given printer (includes bounds) and focus. Read more
source§fn layout(&mut self, _size: Vec2)
fn layout(&mut self, _size: Vec2)
Called once the size for this view has been decided. Read more
source§fn on_event(&mut self, event: Event) -> EventResult
fn on_event(&mut self, event: Event) -> EventResult
Called when an event is received (key press, mouse event, …). Read more
source§fn important_area(&self, size: Vec2) -> Rect
fn important_area(&self, size: Vec2) -> Rect
What part of the view is important and should be visible? Read more
source§fn required_size(&mut self, _constraint: Vec2) -> Vec2
fn required_size(&mut self, _constraint: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions. Read more
source§fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
fn take_focus(&mut self, source: Direction) -> Result<EventResult, CannotFocus>
Attempt to give this view the focus. Read more
source§fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>)
fn call_on_any<'a>(&mut self, selector: &Selector<'_>, callback: AnyCb<'a>)
Runs a closure on the view identified by the given selector. Read more
source§fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<EventResult, ViewNotFound>
fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<EventResult, ViewNotFound>
Moves the focus to the view identified by the given selector. Read more