37 releases (19 breaking)

new 0.21.0 Jan 4, 2025
0.20.0 Dec 22, 2024
0.19.0 Sep 26, 2024
0.18.0 Jul 4, 2024
0.3.1 Nov 7, 2022

#73 in GUI

Download history 334/week @ 2024-09-17 751/week @ 2024-09-24 437/week @ 2024-10-01 365/week @ 2024-10-08 372/week @ 2024-10-15 553/week @ 2024-10-22 524/week @ 2024-10-29 535/week @ 2024-11-05 494/week @ 2024-11-12 668/week @ 2024-11-19 550/week @ 2024-11-26 778/week @ 2024-12-03 858/week @ 2024-12-10 818/week @ 2024-12-17 344/week @ 2024-12-24 694/week @ 2024-12-31

2,856 downloads per month
Used in 18 crates (12 directly)

MIT license

36KB
907 lines

File dialog window (a.k.a. file picker) for egui

Crates.io docs.rs

Taken from the Dotrix project, made into a stand-alone library and modified for more use cases.

Screenshot from 2022-08-18 07-41-11

Example

[dependencies]
egui_file = "0.21"
eframe = "0.30"
use eframe::{
  egui::{CentralPanel, Context},
  App, Frame,
};
use egui_file::FileDialog;
use std::{
  ffi::OsStr,
  path::{Path, PathBuf},
};

#[derive(Default)]
pub struct Demo {
  opened_file: Option<PathBuf>,
  open_file_dialog: Option<FileDialog>,
}

impl App for Demo {
  fn update(&mut self, ctx: &Context, _frame: &mut Frame) {
    CentralPanel::default().show(ctx, |ui| {
      if (ui.button("Open")).clicked() {
        // Show only files with the extension "txt".
        let filter = Box::new({
          let ext = Some(OsStr::new("txt"));
          move |path: &Path| -> bool { path.extension() == ext }
        });
        let mut dialog = FileDialog::open_file(self.opened_file.clone()).show_files_filter(filter);
        dialog.open();
        self.open_file_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.to_path_buf());
          }
        }
      }
    });
  }
}

fn main() {
  let _ = eframe::run_native(
    "File Dialog Demo",
    eframe::NativeOptions::default(),
    Box::new(|_cc| Ok(Box::new(Demo::default()))),
  );
}

Dependencies

~4–9MB
~85K SLoC