[−][src]Trait cursive_core::View
Main trait defining a view behaviour.
This is what you should implement to define a custom View.
Required methods
fn draw(&self, printer: &Printer)
Draws the view with the given printer (includes bounds) and focus.
This is the only required method to implement.
Provided methods
fn layout(&mut self, _: Vec2)
Called once the size for this view has been decided.
It can be used to pre-compute the configuration of child views.
View groups should propagate the information to their children.
At this point, the given size is final and cannot be negociated.
It is guaranteed to be the size available for the call to draw()
.
fn needs_relayout(&self) -> bool
Should return true
if the view content changed since the last call
to layout()
.
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 required_size(&mut self, constraint: Vec2) -> Vec2
Returns the minimum size the view requires with the given restrictions.
This is the main way a view communicate its size to its parent.
Some views have a fixed size, and will ignore the constraint
parameter entirely.
Some views are flexible, and may adapt fully or partially to the constraints.
Default implementation always return (1,1)
.
fn on_event(&mut self, _: Event) -> EventResult
Called when an event is received (key press, mouse event, ...).
You can return an EventResult
:
EventResult::Ignored
means the event was not processed and may be sent to another view.EventResult::Consumed
means the event was consumed and should not be sent to any other view. It may in addition include a callback to be run.
The default implementation just ignores any event.
fn call_on_any<'a>(&mut self, _: &Selector, _: AnyCb<'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.
View groups should implement this to forward the call to each children.
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 (for example mouse events),
Direction::none()
can be used.
Default implementation always return false
.
fn important_area(&self, view_size: Vec2) -> Rect
What part of the view is important and should be visible?
When only part of this view can be visible, this helps determine which part.
It is given the view size (same size given to layout
).
Default implementation return the entire view.
fn type_name(&self) -> &'static str
Returns the type of this view.
Useful when you have a &dyn View
.
View implementation don't usually have to override this.
Implementations
impl dyn View
[src]
pub fn downcast_ref<T: Any>(&self) -> Option<&T>
[src]
Attempts to downcast self
to a concrete type.
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
[src]
Attempts to downcast self
to a concrete type.
pub fn downcast<T: Any>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
[src]
Attempts to downcast Box<Self>
to a concrete type.
pub fn is<T: Any>(&self) -> bool
[src]
Checks if this view is of type T
.
Implementors
impl View for Button
[src]
fn draw(&self, printer: &Printer)
[src]
fn layout(&mut self, size: Vec2)
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn important_area(&self, view_size: Vec2) -> Rect
[src]
fn needs_relayout(&self) -> bool
[src]
impl View for Checkbox
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn draw(&self, printer: &Printer)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
impl View for DebugView
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, _constraint: Vec2) -> Vec2
[src]
fn layout(&mut self, _size: Vec2)
[src]
impl View for Dialog
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, req: Vec2) -> Vec2
[src]
fn layout(&mut self, size: Vec2)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>)
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
fn important_area(&self, _: Vec2) -> Rect
[src]
fn needs_relayout(&self) -> bool
[src]
impl View for DummyView
[src]
impl View for EditView
[src]
fn draw(&self, printer: &Printer)
[src]
fn layout(&mut self, size: Vec2)
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn important_area(&self, _: Vec2) -> Rect
[src]
impl View for FixedLayout
[src]
fn draw(&self, printer: &Printer)
[src]
fn layout(&mut self, _size: Vec2)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn important_area(&self, size: Vec2) -> Rect
[src]
fn required_size(&mut self, _constraint: Vec2) -> Vec2
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>)
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
impl View for LinearLayout
[src]
fn draw(&self, printer: &Printer)
[src]
fn needs_relayout(&self) -> bool
[src]
fn layout(&mut self, size: Vec2)
[src]
fn required_size(&mut self, req: Vec2) -> Vec2
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>)
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
fn important_area(&self, _: Vec2) -> Rect
[src]
impl View for ListView
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, req: Vec2) -> Vec2
[src]
fn layout(&mut self, size: Vec2)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>)
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
fn important_area(&self, size: Vec2) -> Rect
[src]
impl View for MenuPopup
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, req: Vec2) -> Vec2
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn layout(&mut self, size: Vec2)
[src]
fn important_area(&self, size: Vec2) -> Rect
[src]
impl View for Menubar
[src]
fn draw(&self, printer: &Printer)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn important_area(&self, _: Vec2) -> Rect
[src]
impl View for ProgressBar
[src]
impl View for SliderView
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
impl View for StackView
[src]
fn draw(&self, printer: &Printer)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn layout(&mut self, size: Vec2)
[src]
fn required_size(&mut self, size: Vec2) -> Vec2
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>)
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
impl View for TextArea
[src]
fn required_size(&mut self, constraint: Vec2) -> Vec2
[src]
fn draw(&self, printer: &Printer)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn layout(&mut self, size: Vec2)
[src]
fn important_area(&self, _: Vec2) -> Rect
[src]
impl View for TextView
[src]
fn draw(&self, printer: &Printer)
[src]
fn needs_relayout(&self) -> bool
[src]
fn required_size(&mut self, size: Vec2) -> Vec2
[src]
fn layout(&mut self, size: Vec2)
[src]
impl<T: 'static> View for Canvas<T>
[src]
fn draw(&self, printer: &Printer)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn required_size(&mut self, constraint: Vec2) -> Vec2
[src]
fn layout(&mut self, size: Vec2)
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn needs_relayout(&self) -> bool
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
fn important_area(&self, view_size: Vec2) -> Rect
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, cb: AnyCb<'a>)
[src]
impl<T: 'static> View for RadioButton<T>
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn draw(&self, printer: &Printer)
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
impl<T: 'static> View for SelectView<T>
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, _: Vec2) -> Vec2
[src]
fn on_event(&mut self, event: Event) -> EventResult
[src]
fn take_focus(&mut self, _: Direction) -> bool
[src]
fn layout(&mut self, size: Vec2)
[src]
fn important_area(&self, size: Vec2) -> Rect
[src]
impl<T: ViewWrapper> View for T
[src]
fn draw(&self, printer: &Printer)
[src]
fn required_size(&mut self, req: Vec2) -> Vec2
[src]
fn on_event(&mut self, ch: Event) -> EventResult
[src]
fn layout(&mut self, size: Vec2)
[src]
fn take_focus(&mut self, source: Direction) -> bool
[src]
fn call_on_any<'a>(&mut self, selector: &Selector, callback: AnyCb<'a>)
[src]
fn needs_relayout(&self) -> bool
[src]
fn focus_view(&mut self, selector: &Selector) -> Result<(), ()>
[src]
fn important_area(&self, size: Vec2) -> Rect
[src]
impl<V> View for ScrollView<V> where
V: View,
[src]
V: View,