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) { ... }
}

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)

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 (docs/adr/0036-an-event-handler-gets-its-window.md): what the app does about an event beyond its model — write the clipboard, ask for a paste, move focus, reveal or scroll to a row, ask for a frame — is a call on it here, as Node’s update makes on its surface, rather than a field parked for the next view. The verbs land where they say: a clipboard write goes out with this turn’s actions, a focus move or a reveal is seen by the next frame, which the verb asks for. Building a frame (frame) is the runner’s, not the handler’s. 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 the one thing the loop hands out: a Waker the app can clone into any thread. A PTY reader, a file watcher, an LSP client or a socket calls Waker::wake when it has changed what view will show, and the loop draws; nothing else ever wakes it, since it parks between events (backlog C21). The default keeps it: an app with no other thread has no use for one.

Source

fn teardown(&mut self)

Called once, when the main window is going for good — its close button, Quit from the menu or the dock, WindowCommand::Close on it, a pumped runner ended — before run returns or the process exits (backlog F74). The place to keep what the app would otherwise lose with the window: a session, a draft, a position. The frame is over by then: there is no Ui and nothing draws. A crash under run does not reach it; under a pumped runner a panic unwinding through the host drops the runner, and the drop retires it, so it does (backlog RG1) — 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§