1 个不稳定版本
| 0.1.0 | 2021 年 8 月 6 日 |
|---|
572 在 GUI 中
94KB
2.5K SLoC

适用于 Windows、Linux (GTK)、MacOS 和 WASM32 的 Rust 文件对话框。
为什么选择 RFD?
- 它在所有平台上使用 100% 的原生 API,不会在后台启动任何进程。
- 它支持 async/await 语法
- 并且如果有一天您决定将程序移植到浏览器,RFD 也提供了 WASM 支持!
示例
// Sync Dialog
let files = FileDialog::new()
.add_filter("text", &["txt", "rs"])
.add_filter("rust", &["rs", "toml"])
.set_directory("/")
.pick_file();
// Async Dialog
let file = AsyncFileDialog::new()
.add_filter("text", &["txt", "rs"])
.add_filter("rust", &["rs", "toml"])
.set_directory("/")
.pick_file()
.await;
let data = file.read().await;
状态
| API 稳定性 |
|---|
| 🚧 |
| 功能 | Linux | Windows | MacOS [1] | Wasm32 |
|---|---|---|---|---|
| SingleFile | ✔ | ✔ | ✔ | ✔ |
| MultipleFile | ✔ | ✔ | ✔ | ✔ |
| PickFolder | ✔ | ✔ | ✔ | ✖ |
| SaveFile | ✔ | ✔ | ✔ | ✖ |
| 过滤器 | ✔ | ✔ | ✔ | ✔ |
| StartingPath | ✔ | ✔ | ✔ | ✖ |
| Async | ✔ | ✔ | ✔ | ✔ |
[1] Macos 同步对话框与 winit 一起使用时会冻结(与 nfd 相同),由 winit #1779 导致
MacOS Windowed App 和 MacOS NonWindowed App 之间的区别
- Macos 异步对话框需要一个启动的
NSApplication实例,因此只有在像winit、SDL2等窗口环境中打开时,对话框才是真正的异步,否则将回退到同步对话框。 - 还建议在主线程上启动对话框,RFD 可以从任何线程运行对话框,但仅在窗口应用程序中,这会增加一点开销。因此建议:在主线程上启动并在其他线程中等待
- 非窗口应用程序无法从主线程以外的线程启动对话框
- 非窗口应用程序无法启动异步对话框
rfd-extras
即与文件无关的功能
| 功能 | Linux | Windows | MacOS | Wasm32 |
|---|---|---|---|---|
| MessageDialog | ✔ | ✔ | ✔ | ✔ |
| PromptDialog | ||||
| ColorPicker |
依赖关系
~0–3MB
~55K SLoC