Skip to main content

App

Trait App 

Source
pub trait App {
    // Required method
    fn view(&mut self, ui: &mut Ui<'_>);

    // Provided methods
    fn on_event(&mut self, _ev: UiEvent) { ... }
    fn on_event_with(&mut self, ev: UiEvent, _core: &mut Core) { ... }
    fn setup(&mut self, _waker: Waker) { ... }
    fn teardown(&mut self) { ... }
}
Expand description

What a kui application implements: a view that declares each frame and an on_event that answers what the frame produced.

Only view is required. Hand a value of the type to Launcher::run, or to testing::Drive in a test.

Required Methods§

Source

fn view(&mut self, ui: &mut Ui<'_>)

Builds one window’s frame. Called once per open window per frame; ui.window_name() says which ("main" for the launcher’s).

Provided Methods§

Source

fn on_event(&mut self, _ev: UiEvent)

Receives one event the frame produced: a click’s message, a key press, a resize, a window event. Called after the frame, once per event; UiEvent::message reads a #[derive(Message)] back out. The default ignores every event.

Source

fn on_event_with(&mut self, ev: UiEvent, _core: &mut Core)

Self::on_event with the Core of the window the event came from. Override it when answering an event means calling the core: writing the clipboard, asking for a paste, moving focus, revealing a row, asking for a frame. A clipboard write goes out with this turn’s actions; a focus move or a reveal is seen by the next frame. The default calls on_event, so an app that overrides only that one is unchanged.

Source

fn setup(&mut self, _waker: Waker)

Called once, before the window opens, with a Waker the app may clone into any thread. The loop parks between events, so a thread that changed what view will show (a PTY reader, a file watcher, a socket) calls Waker::wake to get a frame drawn. The default drops the waker.

Source

fn teardown(&mut self)

Called once, when the main window is going for good (its close button, Quit, WindowCommand::Close on it, a pumped runner ending), before run returns. Save a session, a draft or a position here; the frame is over, there is no Ui and nothing draws. A crash under run does not reach it; a panic unwinding through a PumpRunner does, and a teardown that panics there aborts. The default does nothing.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§