为 egui 提供了功能齐全且可自定义的文件对话框
Table of contents
This repository provides an easy-to-use and customizable file dialog (a.k.a. file explorer, file picker) for egui.
The file dialog is intended for use by desktop applications, allowing the use of a file dialog directly within the egui application without relying on the operating system's file explorer. This also ensures that the file dialog looks the same and provides the same functionality on all platforms.
The latest changes included in the next release can be found in the CHANGELOG.md file.
Detailed examples that can be run can be found in the examples folder.
The following example shows the basic use of the file dialog with eframe to select a file.
Cargo.toml:
[dependencies]
eframe = "0.36.0"
egui-file-dialog = "0.15.0"main.rs:
…Keybindings can be used in the file dialog for easier navigation.
All keybindings can be configured from the backend with FileDialogKeyBindings and
FileDialog::keybindings.
The following table lists all available keybindings and their default values.
| Name | Description | Default |
|---|---|---|
| submit | Submit the current action or open the currently selected folder | Enter |
| cancel | Cancel the current action | Escape |
| parent | Open the parent directory | ALT + ↑ |
| back | Go back | Mouse button 1 |
ALT + ← |
||
Backspace |
||
| forward | Go forward | Mouse button 2 |
ALT + → |
||
| reload | Reload the file dialog data and the currently open directory | F5 |
| new_folder | Open the dialog to create a new folder | CTRL + N on linux/windows or CMD + N on macOS |
| edit_path | Text edit the current path | / |
| home_edit_path | Open the home directory and start text editing the path | ~ |
| selection_up | Move the selection one item up | ↑ |
| selection_down | Move the selection one item down | ↓ |
| select_all | Select every item in the directory when using the file dialog to select multiple files and folders | CTRL + A on linux/windows or CMD + A on macOS |
Many things can be customized so that the dialog can be used in different situations.
A few highlights of the customization are listed below. For all possible customization
options, see the documentation on
docs.rs.
FileDialog::show_* methodsFileDialog::set_file_icon
(Currently only unicode is supported)FileDialog::keybindings.
See KeybindingsFileDialog::update_with_right_panel_uiSince the dialog uses the egui style to look like the rest of the application,
the appearance can be customized with egui::Style and egui::Context::set_style.
The following example shows how a single file dialog can be customized.
If you need to configure multiple file dialog objects with the same or almost the same
options, it is a good idea to use FileDialogConfig and FileDialog::with_config
(See FileDialogConfig on
docs.rs).
…With the options the dialog then looks like this:
If you want to display your own information in the file dialog, you can
update the file dialog with update_with_right_panel_ui instead of update.
This allows e.g. to display custom image previews or further
information about the selected item. See
custom-right-panel
for the full example.
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
// Update the dialog with a custom right panel
self.file_dialog.update_with_right_panel_ui(ctx, &mut |ui, dialog| {
ui.label("This is a custom label");
ui.add_space(5.0);
ui.label(format!("Currently selected item:\n{:?}", dialog.active_entry()));
});
}For desktop applications it is often necessary to offer different languages. While the dialog currently only offers English labels by default, the labels are fully customizable. This makes it possible to adapt the labels to different languages.
The following example shows how the labels can be changed to display the file dialog
in English or German.
Checkout examples/multilingual for the full example.
…The file dialog currently requires the following persistent data to be stored across multiple file dialog objects:
FileDialog::show_pinned_folders)FileDialog::show_hidden_option)FileDialog::show_system_files_option)If one of the above feature is activated, the data should be saved by the application. Otherwise, frustrating situations could arise for the user and the features would not offer much added value.
All data that needs to be stored permanently is contained in the FileDialogStorage struct.
This struct can be accessed using FileDialog::storage or FileDialog::storage_mut to save or
load the persistent data.
By default the feature serde is enabled, which implements serde::Serialize and
serde::Deserialize for the objects to be saved. However, the objects can also be
accessed without the feature enabled.
The following example shows how the data can be saved with
eframe and the serde
feature enabled.
Checkout examples/persistence for the full example.
…Feel free to contribute to the project. If you have any questions or need help, please open an issue.
This repository uses the nightly version of rustfmt for better code formatting,
specifically using the imports_granularity and group_imports options. Therefore, you need to
run cargo +nightly fmt to automatically format the source files.
This repository uses Git LFS (Large File Storage) to efficiently manage PNG files. Git LFS replaces large files with lightweight pointers in the repository, ensuring the repository remains fast and responsive.
git lfs install to initialize Git LFSgit lfs pull to download all files tracked by Git LFS暂无开放 Issues,或尚未同步最近议题。