-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e18402b
commit 5fa7342
Showing
3 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# egui_inbox | ||
|
||
Utility to send messages to egui views from async functions, callbacks, etc. without having to use interior mutability. | ||
|
||
Example: | ||
|
||
```rust | ||
use eframe::egui; | ||
use egui::CentralPanel; | ||
use egui_inbox::UiInbox; | ||
|
||
pub fn main() -> eframe::Result<()> { | ||
let mut inbox = UiInbox::new(); | ||
let mut state = None; | ||
|
||
eframe::run_simple_native( | ||
"DnD Simple Example", | ||
Default::default(), | ||
move |ctx, _frame| { | ||
CentralPanel::default().show(ctx, |ui| { | ||
inbox.replace(ui, &mut state); | ||
|
||
ui.label(format!("State: {:?}", state)); | ||
if ui.button("Async Task").clicked() { | ||
state = Some("Waiting for async task to complete".to_string()); | ||
let mut inbox_clone = inbox.clone(); | ||
std::thread::spawn(move || { | ||
std::thread::sleep(std::time::Duration::from_secs(1)); | ||
inbox_clone.send(Some("Hello from another thread!".to_string())); | ||
}); | ||
} | ||
}); | ||
}, | ||
) | ||
} | ||
``` |