Trait cursive::view::View [] [src]

pub trait View {
    fn draw(&mut self, printer: &Printer);

    fn on_event(&mut self, Event) -> EventResult { ... }
    fn get_min_size(&mut self, Vec2) -> Vec2 { ... }
    fn needs_relayout(&self) -> bool { ... }
    fn layout(&mut self, Vec2) { ... }
    fn find(&mut self, &Selector) -> Option<&mut Any> { ... }
    fn take_focus(&mut self, source: Direction) -> bool { ... }
}

Main trait defining a view behaviour.

Required Methods

fn draw(&mut self, printer: &Printer)

Draws the view with the given printer (includes bounds) and focus.

Provided Methods

fn on_event(&mut self, Event) -> EventResult

Called when a key was pressed. Default implementation just ignores it.

fn get_min_size(&mut self, Vec2) -> Vec2

Returns the minimum size the view requires with the given restrictions.

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 get_min_size or layout with stable parameters, the children may cache the result themselves and speed up the process anyway.

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 find(&mut self, &Selector) -> Option<&mut Any>

Finds the view pointed to by the given path.

Returns None if the path doesn't lead to a view.

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.

Implementors