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 257/week @ 2024-01-01 635/week @ 2024-01-08 663/week @ 2024-01-15 388/week @ 2024-01-22 324/week @ 2024-01-29 568/week @ 2024-02-05 495/week @ 2024-02-12 1027/week @ 2024-02-19 721/week @ 2024-02-26 519/week @ 2024-03-04 631/week @ 2024-03-11 440/week @ 2024-03-18 558/week @ 2024-03-25 971/week @ 2024-04-01 506/week @ 2024-04-08 570/week @ 2024-04-15

2,655 downloads per month
Used in 13 crates (7 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–11MB
~78K SLoC