34 releases (16 breaking)

0.18.0 Jul 4, 2024
0.17.0 Mar 27, 2024
0.16.3 Feb 29, 2024
0.13.0 Dec 2, 2023
0.3.1 Nov 7, 2022

#55 in GUI

Download history 830/week @ 2024-04-03 547/week @ 2024-04-10 544/week @ 2024-04-17 697/week @ 2024-04-24 576/week @ 2024-05-01 328/week @ 2024-05-08 496/week @ 2024-05-15 971/week @ 2024-05-22 715/week @ 2024-05-29 448/week @ 2024-06-05 430/week @ 2024-06-12 484/week @ 2024-06-19 455/week @ 2024-06-26 707/week @ 2024-07-03 388/week @ 2024-07-10 270/week @ 2024-07-17

1,943 downloads per month
Used in 17 crates (11 directly)

MIT license

30KB
746 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.17"
eframe = "0.27"
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| Box::new(Demo::default())),
  );
}

Dependencies

~4.5–9.5MB
~83K SLoC