From a1ece089ac2788297b7a39b90c48219b685c2a6b Mon Sep 17 00:00:00 2001 From: hacknus Date: Thu, 5 Dec 2024 14:03:24 +0100 Subject: [PATCH] implement `forget_all_stored_images` in `MyApp::update()` --- examples/select_file_with_information_view.rs | 9 ++++++++- src/information_panel.rs | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/select_file_with_information_view.rs b/examples/select_file_with_information_view.rs index f83fbeff..206e553a 100644 --- a/examples/select_file_with_information_view.rs +++ b/examples/select_file_with_information_view.rs @@ -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, @@ -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)); }); } diff --git a/src/information_panel.rs b/src/information_panel.rs index 0131d7a3..98abd7aa 100644 --- a/src/information_panel.rs +++ b/src/information_panel.rs @@ -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()); }