Crate native_dialog

Source
Expand description

§native-dialog

Crates.io Docs.rs License

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

§Installation

cargo add native-dialog

§Usage

use native_dialog::{DialogBuilder, MessageLevel};

let path = DialogBuilder::file()
    .set_location("~/Desktop")
    .add_filter("PNG Image", &["png"])
    .add_filter("JPEG Image", &["jpg", "jpeg"])
    .open_single_file()
    .show()
    .unwrap();

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

// Asyncronous Dialog
let yes = DialogBuilder::message()
    .set_level(MessageLevel::Info)
    .set_title("Do you want to open the file?")
    .set_text(format!("{:#?}", path))
    .confirm()
    .spawn()
    .await
    .unwrap();

if yes {
    do_something(path).await;
}

§Misc

§Ugly or blurry dialogs 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/windows_manifest and examples/windows_features for example.

§Linux/BSD dependencies

The implementation for Linux and BSD requires either Zenity or Kdialog being installed; otherwise the MissingDep error will occur.

Modules§

file
message

Structs§

DialogBuilder
Builder for dialogs.
FileDialogBuilder
Builder for file dialogs.
MessageAlert
MessageConfirm
MessageDialogBuilder
Builder for message dialogs.
OpenMultipleFile
OpenSingleDir
OpenSingleFile
SaveSingleFile

Enums§

Error
MessageLevel
The level of the message in the dialog, which usually affects the color or icon in the dialog.

Traits§

Dialog

Type Aliases§

Result