Best way to update TextView text
- Dominant language
- Rust
- Stars
- 4.8k
- Forks
- 270
- Avg merge
- 5d 19h
- Merged PRs (30d)
- 2
Description
I spent some time trying to figure this out today. I have a custom class that generates a LinearLayout: (trimmed down)
```rust
impl MyLovelyClass {
fn new() -> Self {
Self {
text_message: TextView::new(""),
}
}
fn make_view(&self) -> LinearLayout {
LinearLayout::horizontal()
.child(self.text_message
.min_width(35)
.max_height(1))
}
fn update_data(&mut self, text: &str) {
self.text_message.set_content(text);
}
}
```
Now, this obviously isn't going to work because `.child()` consumes the TextView. This is an ownership problem but the big question is: How can I update a TextView from a second thread? I'll have the data triggered outside the user interface here, so the events that would hand it back to me aren't going to be overly helpful, and I don't think passing a reference to the main Cursive instance for each of my custom objects so that I can use `find_id()` makes a whole lot of sense.
The ProgressBar has an `Arc`, but I have no such luck for TextViews.
Thanks!
Contributor guide
Assessment
This issue has not been assessed yet.