pub trait Widgets<ModelType, ParentModel>where
ModelType: Model<Widgets = Self>,
ParentModel: Model,{
type Root: Debug;
// Required methods
fn init_view(
model: &ModelType,
_components: &ModelType::Components,
sender: Sender<ModelType::Msg>
) -> Self;
fn root_widget(&self) -> Self::Root;
fn view(&mut self, model: &ModelType, sender: Sender<ModelType::Msg>);
// Provided method
fn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets) { ... }
}
Expand description
Define behavior to turn the data of you model into widgets.
This trait and the associated struct can also be implemented by the relm4-macros::widget
macro.
This trait has two generic types, its own model and the model of the parent (which can be ()
).
This allows you to define widgets that can work with different models and parent models.
Most commonly this is used to create reusable components.
Required Associated Types§
sourcetype Root: Debug
type Root: Debug
The root represents the first widget that all other widgets of this app or component are attached to.
The root of the main app must be a gtk::ApplicationWindow
.
Required Methods§
sourcefn init_view(
model: &ModelType,
_components: &ModelType::Components,
sender: Sender<ModelType::Msg>
) -> Self
fn init_view( model: &ModelType, _components: &ModelType::Components, sender: Sender<ModelType::Msg> ) -> Self
Initialize the UI.
Use the parent widgets to connect them to the widgets of this model.
Use the sender to connect UI events and send messages back to modify the model.
sourcefn root_widget(&self) -> Self::Root
fn root_widget(&self) -> Self::Root
Return a clone of the root widget. This is typically a GTK4 widget.
sourcefn view(&mut self, model: &ModelType, sender: Sender<ModelType::Msg>)
fn view(&mut self, model: &ModelType, sender: Sender<ModelType::Msg>)
Update the view to represent the updated model.
Provided Methods§
sourcefn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets)
fn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets)
Optional method to initialize components. This is only useful if you want to attach the widgets of a component to the widgets of this model.