Skip to main content

Crate zero_dialog

Crate zero_dialog 

Source
Expand description

An ultra-lightweight, dependency-free system dialog library. Adds no GUI dependencies, requires no linking, and introduces zero extra code complexity.

Designed to show system-native dialogs as a last-resort user-facing error/exception handler without adding project bloat.

§Usage

Show a modal dialog with title Hello, content World, warning icon, and an OK button (closes when clicked):

zero_dialog::show("Hello", "World", &Default::default());

Show error icon with OK / Cancel buttons and capture user choice:

use zero_dialog::*;

let title = "Fatal Error";
let msg = "Required assets not found, click Ok to exit";
let config = DialogConfig {
    icon: IconKind::Error,
    btn: ButtonKind::OkCancel,
};
let result = zero_dialog::show(title, msg, &config);
match result {
    Ok(Response::Ok) => std::process::exit(1),
    Ok(Response::Cancel) => println!("Cancel"),
    _ => println!("None"),
}

Suitable for use after panic!() to display critical errors.

use std::panic;
use zero_dialog::show;

fn main() {
    panic::set_hook(Box::new(|_| {
        let title = "Error";
        let msg = "Something went wrong";
        let _ = show(title, msg, &Default::default());
    }));

    panic!("Normal panic");
}

Structs§

DialogConfig

Enums§

ButtonKind
Dialog button layout
Error
Possible errors when attempting to show the dialog
IconKind
Response
User response when clicking buttons

Functions§

show
Displays a modal dialog that blocks the calling thread and waits for user input.