40 releases (20 breaking)

0.22.1 Mar 23, 2025
0.21.1 Jan 31, 2025
0.20.0 Dec 22, 2024
0.19.0 Sep 26, 2024
0.3.1 Nov 7, 2022

#54 in GUI

Download history 765/week @ 2024-12-18 328/week @ 2024-12-25 1043/week @ 2025-01-01 853/week @ 2025-01-08 598/week @ 2025-01-15 600/week @ 2025-01-22 772/week @ 2025-01-29 13177/week @ 2025-02-05 84196/week @ 2025-02-12 98551/week @ 2025-02-19 109181/week @ 2025-02-26 101259/week @ 2025-03-05 93980/week @ 2025-03-12 72657/week @ 2025-03-19 74438/week @ 2025-03-26 46762/week @ 2025-04-02

306,259 downloads per month
Used in 18 crates (12 directly)

MIT license

36KB
888 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.22"
eframe = "0.31"
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.5–9.5MB
~90K SLoC