Migration from v0.6 to v0.7

Component changes

Switching between the Component and AsyncComponent traits has been a bit unpleasant in previous versions due to complex errors generated by the code generated by async-trait. To avoid this, the signatures of Component and AsyncComponent were unified.

This means, that Component::init() and SimpleComponent::init() now take Self::Root as owned parameter instead of a reference (&Self::Root). In most places, this just means that you have to remove a &.

Factory changes

ParentInput and forward_to_parent() were removed from FactoryComponent and AsyncFactoryComponent. Instead, factories now support basically the same builder pattern as components.

Example

Replace this:

#![allow(unused)]
fn main() {
#[relm4::factory]
impl FactoryComponent for Counter {
    type ParentInput = AppMsg;

    fn forward_to_parent(output: Self::Output) -> Option<AppMsg> {
        Some(match output {
            CounterOutput::SendFront(index) => AppMsg::SendFront(index),
            CounterOutput::MoveUp(index) => AppMsg::MoveUp(index),
            CounterOutput::MoveDown(index) => AppMsg::MoveDown(index),
        })
    }

    // ...
}

#[relm4::component]
impl SimpleComponent for App {
    // ...

    fn init(
        counter: Self::Init,
        root: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let counters = FactoryVecDeque::new(gtk::Box::default(), sender.input_sender());
        // ...
    }
}
}

With this:

#![allow(unused)]
fn main() {
#[relm4::component]
impl SimpleComponent for App {
    // ...

    fn init(
        counter: Self::Init,
        root: &Self::Root,
        sender: ComponentSender<Self>,
    ) -> ComponentParts<Self> {
        let counters = FactoryVecDeque::builder()
            .launch(gtk::Box::default())
            .forward(sender.input_sender(), |output| match output {
                CounterOutput::SendFront(index) => AppMsg::SendFront(index),
                CounterOutput::MoveUp(index) => AppMsg::MoveUp(index),
                CounterOutput::MoveDown(index) => AppMsg::MoveDown(index),
            });
        // ...
    }
}
}

Other changes

  • set_global_css and set_global_css_from_file are now methods of RelmApp to prevent calling them before initializing GTK
  • The drawing module was moved into the new abstractions module