native-dialog

Crates.io Docs.rs License

A library to display file choosers and message boxes. Supports GNU/Linux, BSD Unix, macOS and Windows.

Installation

cargo add native-dialog

Usage

```rust use native_dialog::{FileDialog, MessageDialog, MessageType};

fn main() { let path = FileDialog::new() .setlocation("~/Desktop") .addfilter("PNG Image", &["png"]) .addfilter("JPEG Image", &["jpg", "jpeg"]) .showopensinglefile() .unwrap();

let path = match path {
    Some(path) => path,
    None => return,
};

let yes = MessageDialog::new()
    .set_type(MessageType::Info)
    .set_title("Do you want to open the file?")
    .set_text(&format!("{:#?}", path))
    .show_confirm()
    .unwrap();

if yes {
    do_something(path);
}

} ```

Misc

Why the dialogs look ugly/blurry on Windows?

Turn on crate features or embed manifests into the .exe to enable visual styling and dpi awareness for your program. Check out examples/windowsmanifest and examples/windowsfeatures for example.

Why the program crashed when opening a dialog on macOS?

The UI framework of macOS (Cocoa) has a limitation that all UI operations must be performed on the main thread.