Trait relm4::Components
source · pub trait Components<ParentModel: ?Sized + Model> {
// Required methods
fn init_components(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self;
fn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets);
}
Expand description
Define how to initialize one or more components.
Typically a struct is used to store multiple components that are child components of the app or another component.
Example
struct AppComponents {
comp1: RelmComponent<Comp1Model, AppModel>,
comp2: RelmComponent<Comp2Model, AppModel>,
}
impl Components<AppModel> for AppComponents {
fn init_components(parent_model: &AppModel, parent_sender: Sender<AppMsg>) -> Self {
AppComponents {
comp1: RelmComponent::new(parent_model, parent_sender.clone()),
comp2: RelmComponent::new(parent_model, parent_sender),
}
}
fn connect_parent(&mut self, parent_widgets: &AppWidgets) {
self.comp1.connect_parent(parent_widgets);
self.comp2.connect_parent(parent_widgets);
}
}
Required Methods§
sourcefn init_components(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self
fn init_components( parent_model: &ParentModel, parent_sender: Sender<ParentModel::Msg> ) -> Self
Initialize your components and workers inside this function.
sourcefn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets)
fn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets)
Connect the components to their parent components widgets (to set the parent window for example).