Skip to main content

ViewModel

Trait ViewModel 

Source
pub trait ViewModel: Send + 'static {
    // Provided methods
    fn on_open(&mut self, cx: &mut Cx<'_, Self>)
       where Self: Sized { ... }
    fn on_close(&mut self, cx: &mut Cx<'_, Self>)
       where Self: Sized { ... }
    fn on_back(&mut self, cx: &mut Cx<'_, Self>) -> bool
       where Self: Sized { ... }
    fn customize(&self, root: &mut Widget) { ... }
}
Expand description

A screen’s state and logic. Implement it (often with no methods) for the type named by the .yui file’s x:ViewModel.

All hooks run on the render thread with the screen locked; use Cx to close the screen, navigate, or get a ScreenHandle for updates from other threads.

Provided Methods§

Source

fn on_open(&mut self, cx: &mut Cx<'_, Self>)
where Self: Sized,

The screen was opened (every time).

Source

fn on_close(&mut self, cx: &mut Cx<'_, Self>)
where Self: Sized,

The screen was closed (by any path).

Source

fn on_back(&mut self, cx: &mut Cx<'_, Self>) -> bool
where Self: Sized,

Esc / back. Return true when handled; false (the default) goes back to the screen this one was navigated from, else closes it.

Source

fn customize(&self, root: &mut Widget)

Escape hatch: imperative changes to the content tree after each binding update. Rarely needed.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§