egui_suspense

Crates.ioegui_suspense
lib.rsegui_suspense
version0.6.0
sourcesrc
created_at2023-11-01 18:32:21.412771
updated_at2024-10-03 09:57:43.857431
descriptionAutomatically show loading and error uis for egui
homepage
repositoryhttps://github.com/lucasmerlin/hello_egui/tree/main/crates/egui_suspense
max_upload_size
id1021503
size134,573
(lucasmerlin)

documentation

README

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();
                    }
                });
            });
        },
    )
}
Commit count: 390

cargo fmt