Skip to main content

View

Trait View 

Source
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 success
  • render — 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§

Source

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§

Source

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.

Source

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.

Source

fn save_state(&mut self, app_state: &mut AppState)

Save the current state of the view before it is closed.

Source

fn render(&self, frame: &mut Frame<'_>, area: Rect, theme: &Theme)

Draw the view into the provided area of the current frame.

Provided Methods§

Source

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.

Source

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.

Implementors§

Source§

impl View for EditorView

Source§

const KIND: ViewKind = crate::views::ViewKind::Primary

Source§

impl View for FileSelector

Source§

const KIND: ViewKind = crate::views::ViewKind::Modal

Source§

impl View for TerminalView

Source§

const KIND: ViewKind = crate::views::ViewKind::Primary