Trait relm4::Widgets

source ·
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§

source

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§

source

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.

source

fn root_widget(&self) -> Self::Root

Return a clone of the root widget. This is typically a GTK4 widget.

source

fn view(&mut self, model: &ModelType, sender: Sender<ModelType::Msg>)

Update the view to represent the updated model.

Provided Methods§

source

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.

Implementations on Foreign Types§

source§

impl<ModelType, ParentModel> Widgets<ModelType, ParentModel> for ()where ModelType: Model<Widgets = ()>, ParentModel: Model,

§

type Root = ()

source§

fn init_view( _model: &ModelType, _components: &ModelType::Components, _sender: Sender<ModelType::Msg> ) -> Self

source§

fn connect_parent(&mut self, _parent_widgets: &ParentModel::Widgets)

source§

fn root_widget(&self) -> Self::Root

source§

fn view(&mut self, _model: &ModelType, _sender: Sender<ModelType::Msg>)

Implementors§