#file-dialog #message #native #macos #boxes #bsd #display

native-dialog

A library to display dialogs. Supports GNU/Linux, BSD Unix, macOS and Windows.

27 releases

0.7.0 Oct 31, 2023
0.6.4 Jun 10, 2023
0.6.3 Jan 22, 2022
0.6.1 Dec 3, 2021
0.4.1 Jul 29, 2020

#51 in GUI

Download history 7715/week @ 2024-07-17 13813/week @ 2024-07-24 11786/week @ 2024-07-31 11143/week @ 2024-08-07 11543/week @ 2024-08-14 12866/week @ 2024-08-21 14250/week @ 2024-08-28 12784/week @ 2024-09-04 7788/week @ 2024-09-11 6176/week @ 2024-09-18 6786/week @ 2024-09-25 7419/week @ 2024-10-02 7736/week @ 2024-10-09 6815/week @ 2024-10-16 5576/week @ 2024-10-23 7428/week @ 2024-10-30

29,340 downloads per month
Used in 41 crates (36 directly)

MIT license

70KB
2K SLoC

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

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);
    }
}

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/windows_manifest and examples/windows_features 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.

Linux dependencies

The Linux implementation of native-dialog requires either Zenity or Kdialog to be installed. Otherwise you'll get a No Implementation error.

Dependencies

~0.4–9.5MB
~108K SLoC