33 releases (15 breaking)

0.17.0 Mar 27, 2024
0.15.0 Feb 6, 2024
0.13.0 Dec 2, 2023
0.12.0 Nov 24, 2023
0.3.1 Nov 7, 2022

#52 in GUI

Download history 765/week @ 2024-02-27 473/week @ 2024-03-05 608/week @ 2024-03-12 481/week @ 2024-03-19 636/week @ 2024-03-26 909/week @ 2024-04-02 508/week @ 2024-04-09 558/week @ 2024-04-16 712/week @ 2024-04-23 627/week @ 2024-04-30 297/week @ 2024-05-07 468/week @ 2024-05-14 815/week @ 2024-05-21 896/week @ 2024-05-28 415/week @ 2024-06-04 426/week @ 2024-06-11

2,655 downloads per month
Used in 16 crates (10 directly)

MIT license

29KB
734 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–10MB
~80K SLoC