Struct relm4::RelmComponent
source · pub struct RelmComponent<Model, ParentModel>where
Model: ComponentUpdate<ParentModel> + 'static,
ParentModel: ModelTrait,
Model::Widgets: WidgetsTrait<Model, ParentModel> + 'static,{ /* private fields */ }
Expand description
A component that can be part of the main application or other components.
A RelmComponent
has its own widget, model and message type
and can send messages to its parent and its children components.
Multiple RelmComponent
s that have the same parent are usually bundled in a struct that implements Components
.
Implementations§
source§impl<Model, ParentModel> RelmComponent<Model, ParentModel>where
Model::Widgets: WidgetsTrait<Model, ParentModel> + 'static,
ParentModel: ModelTrait,
Model: ComponentUpdate<ParentModel> + 'static,
impl<Model, ParentModel> RelmComponent<Model, ParentModel>where Model::Widgets: WidgetsTrait<Model, ParentModel> + 'static, ParentModel: ModelTrait, Model: ComponentUpdate<ParentModel> + 'static,
sourcepub fn new(
parent_model: &ParentModel,
parent_sender: Sender<ParentModel::Msg>
) -> Self
pub fn new( parent_model: &ParentModel, parent_sender: Sender<ParentModel::Msg> ) -> Self
Create a new RelmComponent
.
sourcepub fn connect_parent(&mut self, parent_widgets: &ParentModel::Widgets)
pub fn connect_parent(&mut self, parent_widgets: &ParentModel::Widgets)
Connect the widgets to the widgets of the parent widget.
sourcepub fn send(&self, msg: Model::Msg) -> Result<(), SendError<Model::Msg>>
pub fn send(&self, msg: Model::Msg) -> Result<(), SendError<Model::Msg>>
Send a message to this component. This can be used by the parent to send messages to this component.
sourcepub fn root_widget(
&self
) -> &<Model::Widgets as WidgetsTrait<Model, ParentModel>>::Root
pub fn root_widget( &self ) -> &<Model::Widgets as WidgetsTrait<Model, ParentModel>>::Root
Returns the root widget of this component’s widgets. Can be used by the parent to connect the root widget to the parent’s widgets.
sourcepub fn widgets(&self) -> Option<RefMut<'_, Model::Widgets>>
pub fn widgets(&self) -> Option<RefMut<'_, Model::Widgets>>
Returns a mutable reference to the widgets of this component or None
if
you already have a reference to the widgets.
Use this carefully and make sure the reference to the widgets is dropped after use because
otherwise the view function can’t be called as long you own the widgets (it uses RefCell
internally).