Trait relm::Widget
[−]
[src]
pub trait Widget where
Self: Clone,
Self::Root: Clone + IsA<Widget>,
Self::Msg: Clone + DisplayVariant, { type Model; type ModelParam: Sized; type Msg; type Root; fn model(param: Self::ModelParam) -> Self::Model; fn root(&self) -> &Self::Root; fn update(&mut self, event: Self::Msg, model: &mut Self::Model); fn view(relm: &RemoteRelm<Self>, model: &Self::Model) -> Self; fn init_view(&self) { ... } fn on_add<W: IsA<Widget> + IsA<Object>>(&self, _parent: W) { ... } fn parent_id() -> Option<&'static str> { ... } fn run(model_param: Self::ModelParam) -> Result<(), ()>
where
Self: 'static,
Self::Model: Clone + Send,
Self::ModelParam: Default,
Self::Msg: Send, { ... } fn subscriptions(_relm: &Relm<Self::Msg>) { ... } fn update_command(
_relm: &Relm<Self::Msg>,
_event: Self::Msg,
_model: &mut Self::Model
) { ... } }
Trait to implement to manage widget's events.
Associated Types
type Model
The type of the model.
type ModelParam: Sized
The type of the parameter of the model() function used to initialize the model.
type Msg
The type of the messages sent to the update()
method.
type Root
The type of the root widget.
Required Methods
fn model(param: Self::ModelParam) -> Self::Model
Create the initial model.
fn root(&self) -> &Self::Root
Get the root widget of the view.e. the root widget of the view.
fn update(&mut self, event: Self::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<Self>, model: &Self::Model) -> Self
Create the initial view.
Provided Methods
fn init_view(&self)
Update the view after it is initially created.
This method is only useful when using the #[widget]
attribute, because when not using it,
you can use the view()
method instead.
fn on_add<W: IsA<Widget> + IsA<Object>>(&self, _parent: W)
Method called when the widget is added to its parent.
fn parent_id() -> Option<&'static str>
Get the parent ID.
This is useful for custom Container implementation: when you implement the
Container::add_widget()
, you might want to
insert widgets elsewhere depending of this id.
fn run(model_param: Self::ModelParam) -> Result<(), ()> where
Self: 'static,
Self::Model: Clone + Send,
Self::ModelParam: Default,
Self::Msg: Send,
Self: 'static,
Self::Model: Clone + Send,
Self::ModelParam: Default,
Self::Msg: Send,
Create the window from this widget and start the main loop.
fn subscriptions(_relm: &Relm<Self::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<Self::Msg>,
_event: Self::Msg,
_model: &mut Self::Model
)
_relm: &Relm<Self::Msg>,
_event: Self::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()
.