Taken from the Dotrix project, made into a stand-alone library and modified for more use cases.
toml
[dependencies]
egui_file = "0.9"
eframe = "0.22"
````rust use eframe::{ egui::{CentralPanel, Context}, App, Frame, }; use egui_file::FileDialog; use std::path::PathBuf;
pub struct Demo {
openedfile: Option
impl App for Demo { fn update(&mut self, ctx: &Context, frame: &mut Frame) { CentralPanel::default().show(ctx, |ui| { if (ui.button("Open")).clicked() { let mut dialog = FileDialog::openfile(self.openedfile.clone()); dialog.open(); self.openfile_dialog = Some(dialog); }
if let Some(dialog) = &mut self.open_file_dialog {
if dialog.show(ctx).selected() {
if let Some(file) = dialog.path() {
self.opened_file = Some(file);
}
}
}
});
} }
fn main() { eframe::runnative( "File Dialog Demo", eframe::NativeOptions::default(), Box::new(|cc| Box::new(Demo::default())), ); } ````