-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from fluxxcode/feat/file_dialog
Implement inital file dialog
- Loading branch information
Showing
29 changed files
with
1,944 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
branches: | ||
- master | ||
- develop | ||
|
||
name: Rust | ||
|
||
env: | ||
RUSTFLAGS: "-Dwarnings" | ||
|
||
jobs: | ||
lint-fmt-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Cargo check | ||
run: cargo check | ||
|
||
- name: Rustfmt | ||
run: cargo fmt --all -- --check | ||
|
||
- name: Clippy | ||
run: cargo clippy --all-targets --all-features | ||
|
||
- name: Test | ||
run: cargo test --all-features |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
[workspace] | ||
members = [ | ||
"examples/*" | ||
] | ||
|
||
[package] | ||
name = "egui-file-explorer" | ||
name = "egui-file-dialog" | ||
description = "An easy-to-use file dialog for egui" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["fluxxcode"] | ||
repository = "https://github.com/fluxxcode/egui-file-dialog" | ||
homepage = "https://github.com/fluxxcode/egui-file-dialog" | ||
readme = "README.md" | ||
license = "MIT" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
egui = "0.25.0" | ||
|
||
# Used to fetch user folders | ||
directories = "5.0" | ||
|
||
# Used to fetch disks | ||
sysinfo = { version = "0.30.5", default-features = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Copyright 2024 fluxxcode | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# egui-file-dialog | ||
[![Latest version](https://img.shields.io/crates/v/egui-file-dialog.svg)](https://crates.io/crates/egui-file-dialog) | ||
[![Documentation](https://docs.rs/egui-file-dialog/badge.svg)](https://docs.rs/egui-file-dialog) | ||
[![MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/fluxxcode/egui-file-dialog/blob/master/LICENSE) | ||
|
||
This repository provides an easy-to-use file dialog (a.k.a. file explorer, file picker) for [egui](https://github.com/emilk/egui). This makes it possible to use a file dialog directly in the egui application without having to rely on the file explorer of the operating system. | ||
|
||
<img src="doc/img/demo.png"> | ||
|
||
The goal for the future is that parts of the dialog can be dynamically adapted so that it can be used in different situations. One goal, for example, is that the labels can be dynamically adjusted to support different languages. | ||
|
||
The project is currently in a very early version. Some planned features are still missing and some improvements still need to be made. | ||
|
||
**NOTE**: As long as version 1.0.0 has not yet been reached, even minor version increases may contain breaking changes. | ||
|
||
**Currently only tested on Linux and Windows!** | ||
|
||
## Features | ||
- Select a file or a directory | ||
- Save a file (Prompt user for a destination path) | ||
- Create a new folder | ||
- Navigation buttons to open the parent or previous directories | ||
- Search for items in a directory | ||
- Shortcut for user directories (Home, Documents, ...) and system disks | ||
- Resizable window | ||
|
||
## Example | ||
The following example shows the basic use of the file dialog with [eframe](https://github.com/emilk/egui/tree/master/crates/eframe) to select a file. | ||
|
||
Cargo.toml: | ||
```toml | ||
[dependencies] | ||
eframe = "0.25.0" | ||
egui-file-dialog = "0.1.0" | ||
``` | ||
|
||
main.rs: | ||
```rs | ||
use std::path::PathBuf; | ||
|
||
use eframe::egui; | ||
use egui_file_dialog::FileDialog; | ||
|
||
struct MyApp { | ||
file_dialog: FileDialog, | ||
selected_file: Option<PathBuf>, | ||
} | ||
|
||
impl MyApp { | ||
pub fn new(_cc: &eframe::CreationContext) -> Self { | ||
Self { | ||
// Create a new file dialog object | ||
file_dialog: FileDialog::new(), | ||
selected_file: None, | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
if ui.button("Select file").clicked() { | ||
// Open the file dialog to select a file. | ||
self.file_dialog.select_file(); | ||
} | ||
|
||
ui.label(format!("Selected file: {:?}", self.selected_file)); | ||
|
||
// Update the dialog and check if the user selected a file | ||
if let Some(path) = self.file_dialog.update(ctx).selected() { | ||
self.selected_file = Some(path.to_path_buf()); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
fn main() -> eframe::Result<()> { | ||
eframe::run_native( | ||
"File dialog demo", | ||
eframe::NativeOptions::default(), | ||
Box::new(|ctx| Box::new(MyApp::new(ctx))), | ||
) | ||
} | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "sandbox" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
eframe = { version = "0.25.0", default-features = false, features = ["glow"] } | ||
egui-file-dialog = { version = "0.1.0", path = "../../"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Sandbox app used during development of the file exporter. | ||
|
||
``` | ||
cargo run -p sandbox | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use std::path::PathBuf; | ||
|
||
use eframe::egui; | ||
use egui_file_dialog::{DialogMode, DialogState, FileDialog}; | ||
|
||
struct MyApp { | ||
file_dialog: FileDialog, | ||
|
||
selected_directory: Option<PathBuf>, | ||
selected_file: Option<PathBuf>, | ||
saved_file: Option<PathBuf>, | ||
} | ||
|
||
impl MyApp { | ||
pub fn new(_cc: &eframe::CreationContext) -> Self { | ||
Self { | ||
file_dialog: FileDialog::new(), | ||
|
||
selected_directory: None, | ||
selected_file: None, | ||
saved_file: None, | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
ui.heading("My egui application"); | ||
egui::widgets::global_dark_light_mode_buttons(ui); | ||
|
||
ui.add_space(5.0); | ||
|
||
if ui.button("Select directory").clicked() { | ||
self.file_dialog.select_directory(); | ||
} | ||
ui.label(format!("Selected directory: {:?}", self.selected_directory)); | ||
|
||
ui.add_space(5.0); | ||
|
||
if ui.button("Select file").clicked() { | ||
self.file_dialog.select_file(); | ||
} | ||
ui.label(format!("Selected file: {:?}", self.selected_file)); | ||
|
||
ui.add_space(5.0); | ||
|
||
if ui.button("Save file").clicked() { | ||
self.file_dialog.save_file(); | ||
} | ||
ui.label(format!("File to save: {:?}", self.saved_file)); | ||
|
||
match self.file_dialog.update(ctx).state() { | ||
DialogState::Selected(path) => match self.file_dialog.mode() { | ||
DialogMode::SelectDirectory => self.selected_directory = Some(path), | ||
DialogMode::SelectFile => self.selected_file = Some(path), | ||
DialogMode::SaveFile => self.saved_file = Some(path), | ||
}, | ||
_ => {} | ||
}; | ||
}); | ||
} | ||
} | ||
|
||
fn main() -> eframe::Result<()> { | ||
let options = eframe::NativeOptions { | ||
viewport: egui::ViewportBuilder::default().with_inner_size([1080.0, 720.0]), | ||
..Default::default() | ||
}; | ||
|
||
eframe::run_native( | ||
"My egui application", | ||
options, | ||
Box::new(|ctx| Box::new(MyApp::new(ctx))), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "save_file" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
eframe = { version = "0.25.0", default-features = false, features = ["glow"] } | ||
egui-file-dialog = { version = "0.1.0", path = "../../"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Example showing how to save a file using the file dialog. | ||
|
||
``` | ||
cargo run -p save_file | ||
``` | ||
|
||
![](screenshot.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::path::PathBuf; | ||
|
||
use eframe::egui; | ||
use egui_file_dialog::FileDialog; | ||
|
||
struct MyApp { | ||
file_dialog: FileDialog, | ||
file_path: Option<PathBuf>, | ||
} | ||
|
||
impl MyApp { | ||
pub fn new(_cc: &eframe::CreationContext) -> Self { | ||
Self { | ||
file_dialog: FileDialog::new(), | ||
file_path: None, | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
if ui.button("Save file").clicked() { | ||
self.file_dialog.save_file(); | ||
} | ||
|
||
ui.label(format!("File to save: {:?}", self.file_path)); | ||
|
||
if let Some(path) = self.file_dialog.update(ctx).selected() { | ||
self.file_path = Some(path.to_path_buf()); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
fn main() -> eframe::Result<()> { | ||
eframe::run_native( | ||
"File dialog example", | ||
eframe::NativeOptions::default(), | ||
Box::new(|ctx| Box::new(MyApp::new(ctx))), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "select_directory" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
eframe = { version = "0.25.0", default-features = false, features = ["glow"] } | ||
egui-file-dialog = { version = "0.1.0", path = "../../"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Example showing how to select a directory using the file dialog. | ||
|
||
``` | ||
cargo run -p select_directory | ||
``` | ||
|
||
![](screenshot.png) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::path::PathBuf; | ||
|
||
use eframe::egui; | ||
use egui_file_dialog::FileDialog; | ||
|
||
struct MyApp { | ||
file_dialog: FileDialog, | ||
selected_directory: Option<PathBuf>, | ||
} | ||
|
||
impl MyApp { | ||
pub fn new(_cc: &eframe::CreationContext) -> Self { | ||
Self { | ||
file_dialog: FileDialog::new(), | ||
selected_directory: None, | ||
} | ||
} | ||
} | ||
|
||
impl eframe::App for MyApp { | ||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { | ||
egui::CentralPanel::default().show(ctx, |ui| { | ||
if ui.button("Select directory").clicked() { | ||
self.file_dialog.select_directory(); | ||
} | ||
|
||
ui.label(format!("Selected directory: {:?}", self.selected_directory)); | ||
|
||
if let Some(path) = self.file_dialog.update(ctx).selected() { | ||
self.selected_directory = Some(path.to_path_buf()); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
fn main() -> eframe::Result<()> { | ||
eframe::run_native( | ||
"File dialog example", | ||
eframe::NativeOptions::default(), | ||
Box::new(|ctx| Box::new(MyApp::new(ctx))), | ||
) | ||
} |
Oops, something went wrong.