gyscos / gyscos/cursive

Best way to update TextView text

Open
#178 4 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.