forked from fluxxcode/egui-file-dialog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
FileDialog::{active_entry, update_with_custom_right_panel}
(flu…
…xxcode#170) * Add FileDialog::active_entry * Add FileDialog::update_with_custom_right_panel * Improve doc wording for `FileDialog::active_entry` * Rename `update_with_custom_right_panel` to `update_with_right_panel_ui` * Add FileDialog::active_selected_entries * Add custom-right-panel example * Reposition `active_selected_entries` to be next to `active_entry` * Cross-reference `active_entry` and `active_selected_entries` in the docs * examples/custom-right-panel: Use FileDialog::mode to determine the mode * Fix up import formatting
- Loading branch information
1 parent
c11ce40
commit 07f7a2e
Showing
3 changed files
with
164 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "custom-right-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-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,82 @@ | ||
use std::path::PathBuf; | ||
|
||
use eframe::egui; | ||
use egui_file_dialog::{DialogMode, FileDialog}; | ||
|
||
struct MyApp { | ||
file_dialog: FileDialog, | ||
selected_items: Option<Vec<PathBuf>>, | ||
} | ||
|
||
impl MyApp { | ||
pub fn new(_cc: &eframe::CreationContext) -> Self { | ||
Self { | ||
file_dialog: FileDialog::new(), | ||
selected_items: 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 single").clicked() { | ||
self.file_dialog.select_file(); | ||
} | ||
if ui.button("Select multiple").clicked() { | ||
self.file_dialog.select_multiple(); | ||
} | ||
|
||
ui.label("Selected items:"); | ||
|
||
if let Some(items) = &self.selected_items { | ||
for item in items { | ||
ui.label(format!("{:?}", item)); | ||
} | ||
} else { | ||
ui.label("None"); | ||
} | ||
|
||
self.file_dialog | ||
.update_with_right_panel_ui(ctx, &mut |ui, dia| match dia.mode() { | ||
DialogMode::SelectMultiple => { | ||
ui.heading("Selected items"); | ||
ui.separator(); | ||
egui::ScrollArea::vertical() | ||
.max_height(ui.available_height()) | ||
.show(ui, |ui| { | ||
for item in dia.active_selected_entries() { | ||
ui.small(format!("{item:#?}")); | ||
ui.separator(); | ||
} | ||
}); | ||
} | ||
_ => { | ||
ui.heading("Active item"); | ||
ui.small(format!("{:#?}", dia.active_entry())); | ||
} | ||
}); | ||
|
||
match self.file_dialog.mode() { | ||
DialogMode::SelectMultiple => { | ||
if let Some(items) = self.file_dialog.take_selected_multiple() { | ||
self.selected_items = Some(items); | ||
} | ||
} | ||
_ => { | ||
if let Some(item) = self.file_dialog.take_selected() { | ||
self.selected_items = Some(vec![item]); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
fn main() -> eframe::Result<()> { | ||
eframe::run_native( | ||
"File dialog example", | ||
eframe::NativeOptions::default(), | ||
Box::new(|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