Crates.io | native-dialog |
lib.rs | native-dialog |
version | 0.7.0 |
source | src |
created_at | 2020-06-12 22:38:31.259025 |
updated_at | 2023-10-31 16:53:49.85978 |
description | A library to display dialogs. Supports GNU/Linux, BSD Unix, macOS and Windows. |
homepage | |
repository | https://github.com/balthild/native-dialog-rs |
max_upload_size | |
id | 253435 |
size | 83,571 |
A library to display file choosers and message boxes. Supports GNU/Linux, BSD Unix, macOS and Windows.
cargo add native-dialog
use native_dialog::{FileDialog, MessageDialog, MessageType};
fn main() {
let path = FileDialog::new()
.set_location("~/Desktop")
.add_filter("PNG Image", &["png"])
.add_filter("JPEG Image", &["jpg", "jpeg"])
.show_open_single_file()
.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);
}
}
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.
The UI framework of macOS (Cocoa) has a limitation that all UI operations must be performed on the main thread.
The Linux implementation of native-dialog requires either Zenity or Kdialog to be installed. Otherwise you'll get a No Implementation
error.