Skip to content

Commit

Permalink
revert previous prototype and create information_panel.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
hacknus committed Nov 11, 2024
1 parent a0ab0c3 commit 5ad4cb0
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 262 deletions.
1 change: 0 additions & 1 deletion examples/multilingual/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fn get_labels_german() -> FileDialogLabels {
show_hidden: " Versteckte Dateien anzeigen".to_string(),
show_system_files: " Systemdateien anzeigen".to_string(),

heading_meta: "Metadaten".to_string(),
heading_pinned: "Angeheftet".to_string(),
heading_places: "Orte".to_string(),
heading_devices: "Medien".to_string(),
Expand Down
4 changes: 1 addition & 3 deletions examples/select_file/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ edition = "2021"

[dependencies]
eframe = { workspace = true }
egui_extras = { version = "0.29", features = ["all_loaders", "image", "file"] }
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
egui-file-dialog = { path = "../../" }
egui-file-dialog = { path = "../../"}
8 changes: 2 additions & 6 deletions examples/select_file/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ 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)))
}),
Box::new(|ctx| Ok(Box::new(MyApp::new(ctx)))),
)
}
}
12 changes: 12 additions & 0 deletions examples/select_file_with_information_panel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "select_file_with_information_panel"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
eframe = { workspace = true }
egui_extras = { version = "0.29", features = ["all_loaders", "image", "file"] }
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
egui-file-dialog = { path = "../../" }
7 changes: 7 additions & 0 deletions examples/select_file_with_information_panel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Example showing how to select a file using the file dialog.

```
cargo run -p select_file_with_information_panel
```

![](screenshot.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions examples/select_file_with_information_panel/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use std::path::PathBuf;

use eframe::egui;
use egui_file_dialog::information_panel::InformationPanel;
use egui_file_dialog::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::new().add_file_preview(
"csv",
|ui, text, image| {
ui.label("CSV preview:");
if let Some(content) = text {
egui::ScrollArea::vertical()
.max_height(100.0)
.show(ui, |ui| {
ui.add(
egui::TextEdit::multiline(&mut content.clone()).code_editor(),
);
});
}
},
),
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.select_file();
}

self.file_dialog.set_right_panel_width(200.0);

self.file_dialog
.update_with_right_panel_ui(ctx, &mut |ui, dia| {
self.information_panel.ui(ui, dia);
});

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)))
}),
)
}
9 changes: 1 addition & 8 deletions src/config/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ pub struct FileDialogLabels {
pub show_hidden: String,
/// Text used for the option to show or hide system files.
pub show_system_files: String,

// ------------------------------------------------------------------------
// Right panel:
/// Heading of the "Pinned" sections in the left panel
pub heading_meta: String,

// ------------------------------------------------------------------------
// Left panel:
Expand Down Expand Up @@ -136,9 +131,7 @@ impl Default for FileDialogLabels {
reload: "⟲ Reload".to_string(),
show_hidden: " Show hidden".to_string(),
show_system_files: " Show system files".to_string(),

heading_meta: "Information".to_string(),


heading_pinned: "Pinned".to_string(),
heading_places: "Places".to_string(),
heading_devices: "Devices".to_string(),
Expand Down
4 changes: 4 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ pub struct FileDialogConfig {
/// If the search input in the top panel should be visible.
pub show_search: bool,

/// Set the width of the right panel, if used
pub right_panel_width: Option<f32>,

/// If the sidebar with the shortcut directories such as
/// “Home”, “Documents” etc. should be visible.
pub show_left_panel: bool,
Expand Down Expand Up @@ -257,6 +260,7 @@ impl Default for FileDialogConfig {
show_system_files_option: true,
show_search: true,

right_panel_width: None,
show_left_panel: true,
show_pinned_folders: true,
show_places: true,
Expand Down
Loading

0 comments on commit 5ad4cb0

Please sign in to comment.