#automatic #egui #ui #error #loading #data #async

egui_suspense

Automatically show loading and error uis for egui

6 releases (breaking)

0.6.0 Oct 3, 2024
0.5.0 Jul 3, 2024
0.4.0 Apr 2, 2024
0.3.0 Feb 7, 2024
0.1.0 Nov 1, 2023

#33 in #loading

Download history 111/week @ 2024-06-30 8/week @ 2024-07-07 1/week @ 2024-07-14 38/week @ 2024-07-28 20/week @ 2024-09-15 9/week @ 2024-09-22 156/week @ 2024-09-29 21/week @ 2024-10-06 11/week @ 2024-10-13

199 downloads per month
Used in 2 crates

MIT license

87KB
947 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

~4–12MB
~144K SLoC