Git Product home page Git Product logo

egui_file's People

Contributors

4jx avatar bananaturtlesandwich avatar barugon avatar fabus1184 avatar guillaumeschmid avatar jabeka avatar kaydax avatar mickharrigan avatar red44 avatar reddiepoint avatar sanri avatar tukanoidd avatar willser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

egui_file's Issues

how to use

this is maybe a dumb question due to my limited knowledge of rust, can you give me some help about use this one

/// We derive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
use egui_file::FileDialog;
use std::path::PathBuf;

pub struct TemplateApp {
    // Example stuff:
    label: String,

    #[serde(skip)] // This how you opt-out of serialization of a field
    value: f32,
    opened_file: Option<PathBuf>,
    open_file_dialog: Option<FileDialog>,   

}

impl Default for TemplateApp {
    fn default() -> Self {
        Self {
            // Example stuff:
            label: "Hello World!".to_owned(),
            value: 2.7,
            opened_file: '',
            open_file_dialog: '',   
        }
    }
}

impl TemplateApp {
    /// Called once before the first frame.
    pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
        // This is also where you can customize the look and feel of egui using
        // `cc.egui_ctx.set_visuals` and `cc.egui_ctx.set_fonts`.

        // Load previous app state (if any).
        // Note that you must enable the `persistence` feature for this to work.
        if let Some(storage) = cc.storage {
            return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
        }

        Default::default()
    }
}

impl eframe::App for TemplateApp {
    /// Called by the frame work to save state before shutdown.
    fn save(&mut self, storage: &mut dyn eframe::Storage) {
        eframe::set_value(storage, eframe::APP_KEY, self);
    }

    /// Called each time the UI needs repainting, which may be many times per second.
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        // Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
        // For inspiration and more examples, go to https://emilk.github.io/egui
 
        egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
            // The top panel is often a good place for a menu bar:

            egui::menu::bar(ui, |ui| {
                #[cfg(not(target_arch = "wasm32"))] // no File->Quit on web pages!
                {
                    ui.menu_button("File", |ui| {
                        if ui.button("Quit").clicked() {
                            _frame.close();
                        }
                    });
                    ui.add_space(16.0);
                }

                egui::widgets::global_dark_light_mode_buttons(ui);
            });
        });

        egui::CentralPanel::default().show(ctx, |ui| {
            
            // The central panel the region left after adding TopPanel's and SidePanel's
            ui.heading("eframe template");

            ui.horizontal(|ui| {
                ui.label("Write something: ");
                ui.text_edit_singleline(&mut self.label);
            });

            ui.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("value"));
            if ui.button("Increment").clicked() {
                self.value += 1.0;
            }

            ui.separator();
            if (ui.button("Open")).clicked() {
                let mut dialog = FileDialog::open_file(self.opened_file.clone());
                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);
                  }
                }
              }
              if (ui.button("Open")).clicked() {
                let mut dialog = FileDialog::open_file(self.opened_file.clone());
                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);
                  }
                }
              }

            ui.add(egui::github_link_file!(
                "https://github.com/emilk/eframe_template/blob/master/",
                "Source code."
            ));

            ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
                powered_by_egui_and_eframe(ui);
                egui::warn_if_debug_build(ui);
            });
        });
    }
}

fn powered_by_egui_and_eframe(ui: &mut egui::Ui) {
    ui.horizontal(|ui| {
        ui.spacing_mut().item_spacing.x = 0.0;
        ui.label("Powered by ");
        ui.hyperlink_to("egui", "https://github.com/emilk/egui");
        ui.label(" and ");
        ui.hyperlink_to(
            "eframe",
            "https://github.com/emilk/egui/tree/master/crates/eframe",
        );
        ui.label(".");
    });
}

Filter manually entered path

Currently, the filter option applies only to the files being shown. It would be nice to also check a manually entered path to allow only matching paths to be selected.

One could use the same filter as for the files, or a new one specially for the manually entered path. Of course this can be quite confusing for a user if he can't press save or select or whatever with a manually entered path without any visible reason as to why, but I think this would be on the developer to make sure the user knows what he can enter.

Multiple windows of the same type can not be order-independent

In something like Bevy, different systems might run in an arbitrary order. For standard egui, Windows have a default ID based on the title, but can be given an explicit ID as well. With egui_file, it is likely that multiple open file dialogs will have the same title and therefore the same ID. This is fine if there is only ever one file dialog, but can cause issues if their order changes, or if the first one stops displaying.

I'm sure there are other considerations, but it seems like the user should be able to set the ID in the case that they expect multiple file dialogs and can't guarantee the order or consistency. Another option would be to let the user pass in their own egui::containers::Window and use that, for instance with a show_custom method that takes in a Window parameter and uses it, then they could customize the window however they like before egui_file uses it.

FileDialog doesn't implement fmt::Debug

Hi! I've just found this crate, but the simple problem I'm facing is that FileDialog doesn't implement the Debug trait...

In the docs, they say that Debug should be implemented by all public types (here).

Thanks

Error in Readme

Hi the code in the readme is not in sync with the example. It fails to compile. (See line below). I didn't get a chance to try it but cargo-rdme might be able to let you use the same file so you don't need to do extra work to keep them in sync.

self.opened_file = Some(file.to_path_buf());

Compatibility with `bevy_egui`.

I tried using this crate with bevy_egui, but it doesn't like it. The code is just incompatible. Won't even compile. It is because you require the standard Egui context.

Add Sync trait to type Filter

I'm trying to use this file picker in bevy within a component, but I'm unable to because the Filter type is missing the Sync trait.

Would you be opposed to a PR that adds the Sync trait to Filter?

Cannot compile 0.5.3 under windows

When compiling egui_file under windows, I get the following error:

error[E0609]: no field `show_hidden` on type `&FileDialog`
  --> .cargo\registry\src\github.com-1ecc6299db9ec823\egui_file-0.5.3\src\lib.rs:85:35
   |
85 |       .field("show_hidden", &self.show_hidden)
   |                                   ^^^^^^^^^^^ unknown field
   |
   = note: available fields are: `path`, `path_edit`, `selected_file`, `filename_edit`, `files` ... and 10 others

How to handle `Cancel` or `X`?

I need to close app if file selection was skipped by Cancel or X buttons. How can I do it?
Or how can i disable those buttons?

WASM not supported

You don't say that you work on WASM but you also don't say that you don't. I tried it to see if it would work because when I think of egui I think of cross platform.

Missing field `selected` in initializer of `FileInfo`

Hello, when I try to build my project with this lib I had the following error

 missing field `selected` in initializer of `FileInfo`
   --> src\lib.rs:822:24
    |
822 |             infos.push(FileInfo {
    |                        ^^^^^^^^ missing `selected`

Multiple file selection?

I would like to use this library in my app, but this feature is missing. As of now I rely on rfd, but it would be nice if egui_file supported this.

FileDialog::open resets FileDialog::default_filename

It appears to me that the intended way to use FileDialog::default_filename is prior to calling FileDialog::open, e.g. as follows:

let mut dialog = FileDialog::save_file(None)
    .default_filename("config.toml");
dialog.open();

Unfortunately, since dialog.open() calls dialog.refresh(), which in turn calls dialog.select(None), the above resets the default filename. This can be worked around by setting the default filename after opening the dialog, but the type signatures make this rather non-ergonomic.

I propose modifying FileDialog::select so that filename_edit is not modified if the input is None:

  fn select(&mut self, file: Option<FileInfo>) {
    if let Some(info) = &file {
      self.filename_edit = get_file_name(info).to_owned();
    }
    self.selected_file = file;
  }

Failed to build with nightly-i686-pc-windows-msvc toolchain

When trying to build egui_file with the nightly-i686-pc-windows-msvc toolchain (MSVC 2019), the following error occurs:

libegui_file-ccc8a9d6339a0995.rlib(egui_file-ccc8a9d6339a0995.egui_file.f61f70b0cdbcdb8f-cgu.01.rcgu.o) : error LNK2019: unresolved external symbol _GetLogicalDrives referenced in function __ZN9egui_file10FileDialog7refresh17h1b308e2cd1518bc2E

Could this be an issue on all MSVC toolchains?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.