pub trait View {
const KIND: ViewKind;
// Required methods
fn handle_key(&self, key: KeyEvent) -> Vec<Operation>;
fn handle_operation(
&mut self,
op: &Operation,
settings: &Settings,
) -> Option<Event>;
fn save_state(&mut self, app_state: &mut AppState);
fn render(&self, frame: &mut Frame<'_>, area: Rect, theme: &Theme);
// Provided methods
fn handle_mouse(&self, _mouse: MouseEvent) -> Vec<Operation> { ... }
fn status_bar(&self, _state: &AppState, _bar: &mut StatusBarBuilder) { ... }
}Expand description
Every full-screen view implements this trait.
§Responsibilities
handle_key— translate raw input into operations (no mutation)handle_mouse— translate mouse events into operations (default no-op)handle_operation— apply operations the view owns; emit an event on successrender— draw the current state to the terminal frame
Views own their slice of state. Nobody mutates a view’s internals except
the view itself, through handle_operation.
Required Associated Constants§
Sourceconst KIND: ViewKind
const KIND: ViewKind
The kind of this view: ViewKind::Primary or ViewKind::Modal.
Used by the escape logic to decide whether to revert to the last primary view or to ignore the key press.
Required Methods§
Sourcefn handle_key(&self, key: KeyEvent) -> Vec<Operation>
fn handle_key(&self, key: KeyEvent) -> Vec<Operation>
Translate a key event into zero or more operations.
Must not mutate self — use handle_operation for that.
Sourcefn handle_operation(
&mut self,
op: &Operation,
settings: &Settings,
) -> Option<Event>
fn handle_operation( &mut self, op: &Operation, settings: &Settings, ) -> Option<Event>
Apply a single operation if it is relevant to this view.
Returns Some(event) if the operation was applied (so the event loop
can broadcast the resulting event to subscribers), or None if this
view does not own the operation.
Sourcefn save_state(&mut self, app_state: &mut AppState)
fn save_state(&mut self, app_state: &mut AppState)
Save the current state of the view before it is closed.
Provided Methods§
Sourcefn handle_mouse(&self, _mouse: MouseEvent) -> Vec<Operation>
fn handle_mouse(&self, _mouse: MouseEvent) -> Vec<Operation>
Translate a mouse event into zero or more operations. Default implementation is a no-op; views that support mouse override this.
Sourcefn status_bar(&self, _state: &AppState, _bar: &mut StatusBarBuilder)
fn status_bar(&self, _state: &AppState, _bar: &mut StatusBarBuilder)
Populate the global status bar with view-specific content.
The default implementation is a no-op; views that want to surface information in the status bar override this.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.