News for hackers. Stuff that matters.
Re:Egui 0.27 – easy-to-use immediate mode GUI for Rust by CJefferson on Wednesday March 27, 2024 @09:55AM (#39839130)
I have an app where some tasks can take a long time (like a minute in some cases), so I want the gui to continue responding, and also run my long task in a background thread, then update the GUI when it is finished.

Is there any good examples for this, the examples (not unreasonably), mostly seem to do fairly trivial work.

Re:Egui 0.27 – easy-to-use immediate mode GUI for Rust by emilk on Wednesday March 27, 2024 @10:10AM (#39839341)
The http example at egui.rs uses the `poll_promise` crate to wait for a HTTP request: https://github.com/emilk/egui/blob/master/crates/egui_demo_a...
Re:Egui 0.27 – easy-to-use immediate mode GUI for Rust by CJefferson on Thursday March 28, 2024 @02:24AM (#39848274)
Thanks!
Re:Egui 0.27 – easy-to-use immediate mode GUI for Rust by db48x on Wednesday March 27, 2024 @10:54AM (#39840073)
That’s the key; the thread showing the UI mustn’t do any real work. Instead do the work on another thread and then communicate the status back to the UI thread. Exactly how you do that is up to you; there are plenty of different ways to do it that depend on other choices you’ve made, such as whether you’re using async or not, what async runtime you use, etc, etc.

The very simplest way to do it might be for the UI thread to send the work thread an Arc<AtomicBool>. The work thread can set the bool to true when the work is finished. The UI thread can branch on the value of the bool each frame to decide what to draw. Job done.