[−][src]Trait cursive::View
Main trait defining a view behaviour.
This is what you should implement to define a custom View.
Required methods
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
Draws the view with the given printer (includes bounds) and focus.
This is the only required method to implement.
Provided methods
pub fn layout(&mut self, XY<usize>)
[src]
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()
.
pub fn needs_relayout(&self) -> bool
[src]
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
pub fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
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)
.
pub fn on_event(&mut self, Event) -> EventResult
[src]
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.
pub fn call_on_any(
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
&Selector<'_>,
&'a mut (dyn FnMut(&mut (dyn View + 'static)) + '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.
pub fn focus_view(&mut self, &Selector<'_>) -> Result<(), ViewNotFound>
[src]
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(())
.
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
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
.
pub fn important_area(&self, view_size: XY<usize>) -> Rect
[src]
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.
pub fn type_name(&self) -> &'static str
[src]
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 + 'static
[src]
pub fn downcast_ref<T>(&self) -> Option<&T> where
T: Any,
[src]
T: Any,
Attempts to downcast self
to a concrete type.
pub fn downcast_mut<T>(&mut self) -> Option<&mut T> where
T: Any,
[src]
T: Any,
Attempts to downcast self
to a concrete type.
pub fn downcast<T>(
self: Box<dyn View + 'static, Global>
) -> Result<Box<T, Global>, Box<dyn View + 'static, Global>> where
T: Any,
[src]
self: Box<dyn View + 'static, Global>
) -> Result<Box<T, Global>, Box<dyn View + 'static, Global>> where
T: Any,
Attempts to downcast Box<Self>
to a concrete type.
pub fn is<T>(&self) -> bool where
T: Any,
[src]
T: Any,
Checks if this view is of type T
.
Implementors
impl View for ObservedScreenView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, _: Vec2) -> Vec2
[src]
impl View for Button
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn important_area(&self, view_size: XY<usize>) -> Rect
[src]
pub fn needs_relayout(&self) -> bool
[src]
impl View for Checkbox
[src]
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
impl View for DebugView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, _constraint: XY<usize>) -> XY<usize>
[src]
pub fn layout(&mut self, _size: XY<usize>)
[src]
impl View for Dialog
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, req: XY<usize>) -> XY<usize>
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
pub fn important_area(&self, XY<usize>) -> Rect
[src]
pub fn needs_relayout(&self) -> bool
[src]
impl View for DummyView
[src]
impl View for EditView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn important_area(&self, XY<usize>) -> Rect
[src]
impl View for FixedLayout
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn layout(&mut self, _size: XY<usize>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn important_area(&self, size: XY<usize>) -> Rect
[src]
pub fn required_size(&mut self, _constraint: XY<usize>) -> XY<usize>
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
impl View for LinearLayout
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn needs_relayout(&self) -> bool
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn required_size(&mut self, req: XY<usize>) -> XY<usize>
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
pub fn important_area(&self, XY<usize>) -> Rect
[src]
impl View for ListView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, req: XY<usize>) -> XY<usize>
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
pub fn important_area(&self, size: XY<usize>) -> Rect
[src]
impl View for MenuPopup
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, req: XY<usize>) -> XY<usize>
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn important_area(&self, size: XY<usize>) -> Rect
[src]
impl View for Menubar
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn important_area(&self, XY<usize>) -> Rect
[src]
impl View for ProgressBar
[src]
impl View for SliderView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
impl View for StackView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn required_size(&mut self, size: XY<usize>) -> XY<usize>
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
impl View for TextArea
[src]
pub fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn important_area(&self, XY<usize>) -> Rect
[src]
impl View for TextView
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn needs_relayout(&self) -> bool
[src]
pub fn required_size(&mut self, size: XY<usize>) -> XY<usize>
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
impl<T> View for Canvas<T> where
T: 'static,
[src]
T: 'static,
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn needs_relayout(&self) -> bool
[src]
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
pub fn important_area(&self, view_size: XY<usize>) -> Rect
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
cb: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
cb: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
impl<T> View for RadioButton<T> where
T: 'static,
[src]
T: 'static,
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
impl<T> View for SelectView<T> where
T: 'static,
[src]
T: 'static,
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, XY<usize>) -> XY<usize>
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn take_focus(&mut self, Direction) -> bool
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn important_area(&self, size: XY<usize>) -> Rect
[src]
impl<T> View for T where
T: ViewWrapper,
[src]
T: ViewWrapper,
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn required_size(&mut self, req: XY<usize>) -> XY<usize>
[src]
pub fn on_event(&mut self, ch: Event) -> EventResult
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn take_focus(&mut self, source: Direction) -> bool
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
callback: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn needs_relayout(&self) -> bool
[src]
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
pub fn important_area(&self, size: XY<usize>) -> Rect
[src]
impl<V> View for ScrollView<V> where
V: View,
[src]
V: View,
pub fn draw(&self, printer: &Printer<'_, '_>)
[src]
pub fn on_event(&mut self, event: Event) -> EventResult
[src]
pub fn layout(&mut self, size: XY<usize>)
[src]
pub fn needs_relayout(&self) -> bool
[src]
pub fn required_size(&mut self, constraint: XY<usize>) -> XY<usize>
[src]
pub fn call_on_any(
&mut self,
selector: &Selector<'_>,
cb: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
[src]
&mut self,
selector: &Selector<'_>,
cb: &'a mut (dyn FnMut(&mut (dyn View + 'static)) + 'a)
)
pub fn focus_view(
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>
[src]
&mut self,
selector: &Selector<'_>
) -> Result<(), ViewNotFound>