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 2de8627
Show file tree
Hide file tree
Showing 14 changed files with 462 additions and 260 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 = "../../"}
6 changes: 1 addition & 5 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)))
}),
)
}
7 changes: 0 additions & 7 deletions src/config/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ pub struct FileDialogLabels {
/// 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:
/// Heading of the "Pinned" sections in the left panel
Expand Down Expand Up @@ -137,8 +132,6 @@ impl Default for FileDialogLabels {
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 2de8627

Please sign in to comment.