-
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.
feat: implement information view and preview for files (#184)
* initial implementation of file information display * revert previous prototype and create information_panel.rs * add meta data grid * update meta_data * revert public config and selected item * only read 1000 characters of text files and implement Markdown as an example * add separators * introduce info_panel feature * upload test_image * implement metadata, markdown and image preview * metadata in ScrollArea and only display size for files, not directories * clean up, add doc and add folder icon as preview * removed profiles, not used anymore * image crate needs to be loaded always, because of the Image metadata loaded in directory_content.rs * only load image crate when using info_panel feature * only load text content once. show icon if no preview is available * extend preview for jpeg and jpg * extension to lowercase, so it does not matter how they are stored on the file system. added color space * rapidly decreased loading times of directories using image-meta crate instead of image crate * indexmap instead of hashmap, so that metadata is always in the same order * cargo clippy * remove unused doc * Update Cargo.toml Co-authored-by: Nicolas <[email protected]> * workflow fix * reformat * text content is now only loaded for the selected file and then stored in the ActiveDirectory * not hard-coding max chars of text preview * fix width and compilation errors * implement custom metadata loader * remove unused dependency * code review by bircni * required for image loader * add for cargo machete. image crate is required per documentation of egui loaders * remove md render * use picked instead of selected * rename example * rename example * create metadata struct * rustfmt * implement content_mut * fix typo * implement `InfoPanelEntry` struct * change feature name to information_view * move format_pixels() to information_panel.rs * add screenshot and remove test_image * remove print * change date formatting * Update examples/select_file_with_information_view/README.md Co-authored-by: Jannis <[email protected]> * Update src/data/information_panel.rs Co-authored-by: Jannis <[email protected]> * Update src/data/information_panel.rs Co-authored-by: Jannis <[email protected]> * add docs * introduced path_buf variable * code review * rename handler * set image max width to be as high as the panel is wide * show icon for all files * don't set width of meta grid * adapt for latest example structure * Revert "don't set width of meta grid" This reverts commit 0c4eb84. * add comment for image crate * clippy * remove images if more than 10 are loaded * move information_panel.rs * rustfmt * better doc for example * update README.md * implement `forget_all_stored_images` * implement `forget_all_stored_images` in `MyApp::update()` * update Cargo.toml * Update examples/README.md Co-authored-by: Jannis <[email protected]> * pick file rename * remove hardcoded icon width * id with `FileDialog` as parent * fix id * windows should always take up the same amount of space * Update src/information_panel.rs Co-authored-by: Jannis <[email protected]> * Update src/information_panel.rs Co-authored-by: Jannis <[email protected]> * extract image display function * rustfmt * all previews should have the same size * Update examples/pick_file_with_information_view.rs Co-authored-by: Jannis <[email protected]> * Update Cargo.toml Co-authored-by: Jannis <[email protected]> * fix typo --------- Co-authored-by: Nicolas <[email protected]> Co-authored-by: Jannis <[email protected]>
- Loading branch information
1 parent
042efb2
commit 300cb6f
Showing
10 changed files
with
630 additions
and
11 deletions.
There are no files selected for viewing
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
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
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,78 @@ | ||
use std::path::PathBuf; | ||
|
||
use eframe::egui; | ||
use egui_file_dialog::information_panel::InformationPanel; | ||
use egui_file_dialog::{DialogState, FileDialog}; | ||
|
||
struct MyApp { | ||
file_dialog: FileDialog, | ||
information_panel: InformationPanel, | ||
selected_file: Option<PathBuf>, | ||
} | ||
|
||
impl MyApp { | ||
pub fn new(_cc: &eframe::CreationContext) -> Self { | ||
Self { | ||
file_dialog: FileDialog::new(), | ||
information_panel: InformationPanel::default() | ||
.add_file_preview("csv", |ui, item| { | ||
ui.label("CSV preview:"); | ||
if let Some(mut content) = item.content() { | ||
egui::ScrollArea::vertical() | ||
.max_height(ui.available_height()) | ||
.show(ui, |ui| { | ||
ui.add(egui::TextEdit::multiline(&mut content).code_editor()); | ||
}); | ||
} | ||
}) | ||
// add additional metadata loader | ||
.add_metadata_loader("pdf", |other_meta_data, path| { | ||
// as a simple example, just show the Filename of the PDF | ||
other_meta_data.insert("PDF Filename".to_string(), format!("{path:?}")); | ||
}), | ||
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() { | ||
self.file_dialog.pick_file(); | ||
} | ||
|
||
self.file_dialog.set_right_panel_width(200.0); | ||
|
||
if let Some(path) = self | ||
.file_dialog | ||
.update_with_right_panel_ui(ctx, &mut |ui, dia| { | ||
self.information_panel.ui(ui, dia); | ||
}) | ||
.picked() | ||
{ | ||
self.selected_file = Some(path.to_path_buf()); | ||
} | ||
|
||
match self.file_dialog.state() { | ||
DialogState::Closed | DialogState::Cancelled => { | ||
self.information_panel.forget_all_stored_images(ui); | ||
} | ||
_ => {} | ||
} | ||
|
||
ui.label(format!("Selected file: {:?}", self.selected_file)); | ||
}); | ||
} | ||
} | ||
|
||
fn main() -> eframe::Result<()> { | ||
eframe::run_native( | ||
"File dialog example", | ||
eframe::NativeOptions::default(), | ||
Box::new(|ctx| { | ||
egui_extras::install_image_loaders(&ctx.egui_ctx); | ||
Ok(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
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
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 |
---|---|---|
|
@@ -5,4 +5,5 @@ mod disks; | |
pub use disks::{Disk, Disks}; | ||
|
||
mod user_directories; | ||
|
||
pub use user_directories::UserDirectories; |
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
Oops, something went wrong.