pub trait Widgets<ModelType, ParentModel> where
ModelType: Model<Widgets = Self>,
ParentModel: Model, {
type Root: Debug;
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>);
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.
Associated Types
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
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.
fn root_widget(&self) -> Self::Root
fn root_widget(&self) -> Self::Root
Return a clone of the root widget. This is typically a GTK4 widget.
Provided methods
fn 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.