Struct egui_file_dialog::FileDialog
source · pub struct FileDialog { /* private fields */ }Expand description
Represents a file dialog instance.
The FileDialog instance can be used multiple times and for different actions.
§Examples
use egui_file_dialog::FileDialog;
struct MyApp {
file_dialog: FileDialog,
}
impl MyApp {
fn update(&mut self, ctx: &egui::Context, ui: &mut egui::Ui) {
if ui.button("Select a file").clicked() {
self.file_dialog.select_file();
}
if let Some(path) = self.file_dialog.update(ctx).selected() {
println!("Selected file: {:?}", path);
}
}
}Implementations§
source§impl FileDialog
impl FileDialog
sourcepub fn initial_directory(self, directory: PathBuf) -> Self
pub fn initial_directory(self, directory: PathBuf) -> Self
Sets the first loaded directory when the dialog opens. If the path is a file, the file’s parent directory is used. If the path then has no parent directory or cannot be loaded, the user will receive an error. However, the user directories and system disk allow the user to still select a file in the event of an error.
Relative and absolute paths are allowed, but absolute paths are recommended.
sourcepub fn default_window_size(self, size: Vec2) -> Self
pub fn default_window_size(self, size: Vec2) -> Self
Sets the default size of the window.
sourcepub fn default_file_name(self, name: &str) -> Self
pub fn default_file_name(self, name: &str) -> Self
Sets the default file name when opening the dialog in DialogMode::SaveFile mode.
sourcepub fn open(&mut self, mode: DialogMode, show_files: bool) -> Result<()>
pub fn open(&mut self, mode: DialogMode, show_files: bool) -> Result<()>
Opens the file dialog in the given mode with the given options. This function resets the file dialog and takes care for the variables that need to be set when opening the file dialog.
Returns the result of the operation to load the initial directory.
The show_files parameter will be ignored when the mode equals DialogMode::SelectFile.
sourcepub fn select_directory(&mut self)
pub fn select_directory(&mut self)
Shortcut function to open the file dialog to prompt the user to select a directory.
If used, no files in the directories will be shown to the user.
Use the open() method instead, if you still want to display files to the user.
This function resets the file dialog. Configuration variables such as
initial_directory are retained.
The function ignores the result of the initial directory loading operation.
sourcepub fn select_file(&mut self)
pub fn select_file(&mut self)
Shortcut function to open the file dialog to prompt the user to select a file.
This function resets the file dialog. Configuration variables such as
initial_directory are retained.
The function ignores the result of the initial directory loading operation.
sourcepub fn save_file(&mut self)
pub fn save_file(&mut self)
Shortcut function to open the file dialog to prompt the user to save a file.
This function resets the file dialog. Configuration variables such as
initial_directory are retained.
The function ignores the result of the initial directory loading operation.
sourcepub fn mode(&self) -> DialogMode
pub fn mode(&self) -> DialogMode
Returns the mode the dialog is currently in.
sourcepub fn state(&self) -> DialogState
pub fn state(&self) -> DialogState
Returns the state the dialog is currently in.