Skip to content

Commit

Permalink
Release egui_inbox
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Aug 20, 2023
1 parent e18402b commit 5fa7342
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Source code in [fancy-example](fancy-example).
- Drag & drop sorting library for egui
- released on [crates.io](https://crates.io/crates/egui_dnd)

- [egui_inbox](crates/egui_inbox)
- Simple utility for sending messages to egui uis from other threads / async functions
- released on [crates.io](https://crates.io/crates/egui_inbox)

## **Experimental** Crates

- [egui_virtual_list](crates/egui_virtual_list)
Expand All @@ -35,8 +39,5 @@ Source code in [fancy-example](fancy-example).
- Adds flexbox layout to egui using [taffy](https://github.com/DioxusLabs/taffy)
- Highly experimental, unreleased

- [egui_inbox](crates/egui_inbox)
- Simple utility for sending messages to egui uis from other threads / async functions

- [hello_egui_utils](crates/hello_egui_utils)
- Collection of utilities used by the other crates
3 changes: 3 additions & 0 deletions crates/egui_inbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
name = "egui_inbox"
version = "0.1.0"
edition = "2021"
description = "Utility to send messages to egui views from async functions, callbacks, etc. without having to use interior mutability."
license = "MIT"
repository = "https://github.com/lucasmerlin/hello_egui/tree/main/crates/egui_inbox"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
36 changes: 36 additions & 0 deletions crates/egui_inbox/README.md
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()));
});
}
});
},
)
}
```

0 comments on commit 5fa7342

Please sign in to comment.