4 releases (breaking)

0.4.0 Apr 2, 2024
0.3.0 Feb 7, 2024
0.2.0 Jan 21, 2024
0.1.0 Nov 1, 2023

#878 in Data structures

Download history 1/week @ 2024-01-18 2/week @ 2024-02-01 7/week @ 2024-02-15 24/week @ 2024-02-22 11/week @ 2024-02-29 4/week @ 2024-03-07 7/week @ 2024-03-14 103/week @ 2024-03-28 32/week @ 2024-04-04

144 downloads per month
Used in hello_egui

MIT license

73KB
731 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

~5–14MB
~136K SLoC