Trait vizia_core::model::Model

source ·
pub trait Model: 'static + Sized {
    // Provided methods
    fn build(self, cx: &mut Context) { ... }
    fn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event) { ... }
    fn name(&self) -> Option<&'static str> { ... }
}
Expand description

A trait implemented by application data in order to respond to events and mutate state.

§Examples

pub struct AppData {
    count: i32,
}

enum AppEvent {
    Increment,
    Decrement,
}

impl Model for AppData {
    fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
        event.map(|app_event, _| match app_event {
            AppEvent::Increment => {
                self.count += 1;
            }

            AppEvent::Decrement => {
                self.count -= 1;
            }
        });
    }
}

Provided Methods§

source

fn build(self, cx: &mut Context)

Build the model data into the application tree.

§Examples
fn main() {
    Application::new(|cx|{
        AppData::default().build(cx);
    }).run();  
}
source

fn event(&mut self, cx: &mut EventContext<'_>, event: &mut Event)

Respond to events in order to mutate the model data.

§Examples
impl Model for AppData {
    fn event(&mut self, cx: &mut EventContext, event: &mut Event) {
        event.map(|app_event, _| match app_event {
            AppEvent::Increment => {
                self.count += 1;
            }

            AppEvent::Decrement => {
                self.count -= 1;
            }
        });
    }
}
source

fn name(&self) -> Option<&'static str>

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Model for ()

Implementors§

source§

impl Model for Environment

source§

impl Model for ModalModel

source§

impl Model for PopupData

source§

impl<T> Model for Keymap<T>
where T: 'static + Clone + PartialEq + Send + Sync,