8 releases (breaking)

0.8.0 Feb 7, 2025
0.7.0 Dec 19, 2024
0.6.0 Oct 3, 2024
0.5.0 Jul 3, 2024
0.1.0 Nov 1, 2023

#1261 in GUI

Download history 19/week @ 2024-11-23 8/week @ 2024-11-30 10/week @ 2024-12-07 97/week @ 2024-12-14 16/week @ 2024-12-21 1/week @ 2024-12-28 4/week @ 2025-01-04 5/week @ 2025-01-11 72/week @ 2025-02-01 59/week @ 2025-02-08 16/week @ 2025-02-15 6/week @ 2025-02-22 8/week @ 2025-03-01 20/week @ 2025-03-08

52 downloads per month
Used in 2 crates

MIT license

90KB
973 lines

egui_suspense

egui_ver Latest version Documentation unsafe forbidden License

A helper to display loading, error and retry uis when waiting for asynchronous data.

Minimal example

use eframe::egui;
use egui::CentralPanel;
use egui_suspense::EguiSuspense;

pub fn main() -> eframe::Result<()> {
    let mut suspense = EguiSuspense::reloadable(|cb| {
        std::thread::spawn(move || {
            std::thread::sleep(std::time::Duration::from_secs(1));
            cb(if rand::random() {
                Ok("Hello".to_string())
            } else {
                Err("OOPSIE WOOPSIE!".to_string())
            });
        });
    });

    eframe::run_simple_native(
        "DnD Simple Example",
        Default::default(),
        move |ctx, _frame| {
            CentralPanel::default().show(ctx, |ui| {
                
                // This will show a spinner while loading and an error message with a 
                // retry button if the callback returns an error.
                suspense.ui(ui, |ui, data, state| {
                    ui.label(format!("Data: {:?}", data));

                    if ui.button("Reload").clicked() {
                        state.reload();
                    }
                });
            });
        },
    )
}

Dependencies

~8–46MB
~751K SLoC