Trait relm::Widget
[−]
[src]
pub trait Widget<MSG: Clone + DisplayVariant> where Self: Sized, Self::Container: Clone + IsA<Widget> { type Container; type Model; fn container(&self) -> &Self::Container; fn model() -> Self::Model; fn update(&mut self, event: MSG, model: &mut Self::Model); fn view(relm: RemoteRelm<MSG>, model: &Self::Model) -> Self; fn subscriptions(_relm: &Relm<MSG>) { ... } fn update_command(_relm: &Relm<MSG>, _event: MSG, _model: &mut Self::Model) { ... } }
Trait to implement to manage widget's events.
Associated Types
Required Methods
fn container(&self) -> &Self::Container
Get the containing widget, i.e. the parent widget of the view.
fn model() -> Self::Model
Create the initial model.
fn update(&mut self, event: MSG, model: &mut Self::Model)
Method called when a message is received from an event.
Note
This method is called in the GTK+ thread, so that you can update widgets.
fn view(relm: RemoteRelm<MSG>, model: &Self::Model) -> Self
Create the initial view.
Provided Methods
fn subscriptions(_relm: &Relm<MSG>)
Connect the subscriptions.
Subscriptions are Future
/Stream
that are spawn when the widget is created.
Note
This method is called in the tokio thread, so that you can spawn Future
s and Stream
s.
fn update_command(_relm: &Relm<MSG>, _event: MSG, _model: &mut Self::Model)
Connect Future
s or Stream
s when receiving an event.
Warning
This method is executed in the tokio thread: hence, you must spawn any futures in this
method, not in Widget::update()
.