Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/native-dialog-rs/native-dialog-rs
https://github.com/native-dialog-rs/native-dialog-rs
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/native-dialog-rs/native-dialog-rs
- Owner: native-dialog-rs
- License: mit
- Created: 2020-06-12T22:39:33.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-05-01T03:05:29.000Z (6 months ago)
- Last Synced: 2024-11-05T11:10:15.529Z (7 days ago)
- Language: Rust
- Size: 148 KB
- Stars: 210
- Watchers: 2
- Forks: 28
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# native-dialog
[![Crates.io](https://img.shields.io/crates/v/native-dialog.svg)](https://crates.io/crates/native-dialog)
[![Docs.rs](https://docs.rs/native-dialog/badge.svg)](https://docs.rs/native-dialog)
[![License](https://img.shields.io/crates/l/native-dialog.svg)](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()
.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](examples/windows_manifest) and [examples/windows_features](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.