Skip to content

Commit

Permalink
implement forget_all_stored_images in MyApp::update()
Browse files Browse the repository at this point in the history
  • Loading branch information
hacknus committed Dec 5, 2024
1 parent f950d1b commit a1ece08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion examples/select_file_with_information_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use eframe::egui;
use egui_file_dialog::information_panel::InformationPanel;
use egui_file_dialog::FileDialog;
use egui_file_dialog::{DialogState, FileDialog};

struct MyApp {
file_dialog: FileDialog,
Expand Down Expand Up @@ -54,6 +54,13 @@ impl eframe::App for MyApp {
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));
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/information_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ impl InformationPanel {
self.stored_images.shift_remove_index(0);
}

#[allow(dead_code)]
fn forget_all_stored_images(&mut self, ui: &Ui) {
/// removes all loaded preview images from the egui-loaders to reduce memory usage.
pub fn forget_all_stored_images(&mut self, ui: &Ui) {
for image in &self.stored_images {
ui.ctx().forget_image(format!("file://{image}").as_str());
}
Expand Down

0 comments on commit a1ece08

Please sign in to comment.