-
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.
revert previous prototype and create information_panel.rs
- Loading branch information
Showing
14 changed files
with
464 additions
and
262 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
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,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 = "../../" } |
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 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.
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,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))) | ||
}), | ||
) | ||
} |
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
Oops, something went wrong.