antoyo / relm

Idiomatic, GTK+-based, GUI library, inspired by Elm, written in Rust
MIT License
2.43k stars 78 forks source link

How to send Message to a child #216

Closed MGlolenstine closed 4 years ago

MGlolenstine commented 4 years ago

This is a continuation of #204 ... Now I have everything set up for the ListView, but I'm having some problems adding to the said list. It works fine to add it to the constructor, but if I make a public method add_entry, I can't call it, as I get relm::component::Component<ListView> instead of just ListView, that is when I get it like this

#[name="list"]
ListView(vec![]){
},
fn update(&mut self, event: ListMsg){
    self.list;
}

Now I tried adding an entry using this

fn add_entry(&mut self, item: String){
    self.model.values.push(item);
}

but I can't call it.

How can I send a message or call a method inside a component?

PS: If I understand this correctly, when the button is clicked, it sends a message to the child, in this case, counter1. How would I do that via code?

antoyo commented 4 years ago

For every *-attribute.rs example, there's one without using the #[widget] attribute.

Also, there's a emit() method on a component to send it a message. It's even in the doc.

antoyo commented 4 years ago

Do you need more help or can we close this issue?

MGlolenstine commented 4 years ago

I think we can close it, I haven't gotten around to testing it, but I'll reopen, if more questions arise.

Thanks!

MGlolenstine commented 4 years ago

I just came around to testing it, and it works well with the emit().

Thanks!