Trait cursive::view::View
[−]
[src]
pub trait View { fn draw(&self, printer: &Printer); fn on_event(&mut self, Event) -> EventResult { ... } fn required_size(&mut self, constraint: Vec2) -> Vec2 { ... } fn needs_relayout(&self) -> bool { ... } fn layout(&mut self, Vec2) { ... } fn call_on_any<'a>(&mut self, _: &Selector, _: Box<FnMut(&mut Any) + 'a>) { ... } fn focus_view(&mut self, &Selector) -> Result<(), ()> { ... } fn take_focus(&mut self, source: Direction) -> bool { ... } }
Main trait defining a view behaviour.
Required Methods
Provided Methods
fn on_event(&mut self, Event) -> EventResult
Called when a key was pressed.
Default implementation just ignores it.
fn required_size(&mut self, constraint: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions.
If the view is flexible (it has multiple size options), it can try
to return one that fits the given constraint
.
It's also fine to ignore it and return a fixed value.
Default implementation always return (1,1)
.
fn needs_relayout(&self) -> bool
Returns true
if the view content changed since last layout phase.
This is mostly an optimisation for views where the layout phase is expensive.
- Views can ignore it and always return true (default implementation). They will always be assumed to have changed.
- View Groups can ignore it and always re-layout their children.
- If they call
required_size
orlayout
with stable parameters, the children may cache the result themselves and speed up the process anyway.
- If they call
fn layout(&mut self, Vec2)
Called once the size for this view has been decided,
View groups should propagate the information to their children.
fn call_on_any<'a>(&mut self, _: &Selector, _: Box<FnMut(&mut Any) + 'a>)
Runs a closure on the view identified by the given selector.
See Finder::call_on
for a nicer interface, implemented for all views.
If the selector doesn't find a match, the closure will not be run.
Default implementation is a no-op.
fn focus_view(&mut self, &Selector) -> Result<(), ()>
Moves the focus to the view identified by the given selector.
Returns Ok(())
if the view was found and selected.
Default implementation simply returns Err(())
.
fn take_focus(&mut self, source: Direction) -> bool
This view is offered focus. Will it take it?
source
indicates where the focus comes from.
When the source is unclear, Front
is usually used.
Default implementation always return false
.
Implementors
impl<T: ViewWrapper> View for T
impl View for Button
impl<T> View for Canvas<T>
impl View for Checkbox
impl View for Dialog
impl View for DummyView
impl View for EditView
impl View for LinearLayout
impl View for ListView
impl View for Menubar
impl View for MenuPopup
impl View for ProgressBar
impl<T> View for RadioButton<T>
impl<T: 'static> View for SelectView<T>
impl View for SliderView
impl View for StackView
impl View for TextArea
impl View for TextView