Add custom user events to eframe event loop
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
Just like `request_repaint` there could be `send_message` that takes a `Box` which is passed to the `eframe::App`.
### Discussed in https://github.com/emilk/egui/discussions/2679
Originally posted by **Dicklessgreat** February 5, 2023
Can I use main thread not only for GUI repaint but also for other things with eframe?
In my head, I want something like...
```
loop {
match message_manager.get_message_if_there_is_one() {
Message::Repaint => { app.update(ctx, frame); },
Message::AutoSave => { my_model.save_state(); },
...
}
}
```
and other part of my module, let's say `timer` crate.
```
fn auto_save(&self) {
if self.check_time() {
message_manager.post_message(Message::AutoSave);
}
}
```
It seems like `Context::request_repaint()` can post `Message::Repaint`, but can I invoke other tasks to the main thread?
Or, should I implement custom eframe-like crate?
Contributor guide
Research direction
Start by reading the eframe event-loop implementation and the existing Context::request_repaint path, then review discussion #2679 for the proposed main-thread message use case. Define how send_message carries a Box and how messages are delivered to eframe::App; done means custom user events reliably reach the app without breaking repaint behavior across supported targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100