Skip to content

Commit

Permalink
extract image display function
Browse files Browse the repository at this point in the history
  • Loading branch information
hacknus committed Dec 5, 2024
1 parent 13ec6a8 commit 4fdda5f
Showing 1 changed file with 27 additions and 39 deletions.
66 changes: 27 additions & 39 deletions src/information_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,59 +139,23 @@ impl Default for InformationPanel {
"jpg".to_string(),
Box::new(
|ui: &mut Ui, item: &InfoPanelEntry, stored_images: &mut IndexSet<String>| {
ui.label("Image");
stored_images.insert(format!("{}", item.directory_entry.as_path().display()));
let image = egui::Image::new(format!(
"file://{}",
item.directory_entry.as_path().display()
));
let size = Vec2 {
x: ui.available_width(),
y: ui.available_width() / 4.0 * 3.0,
};
ui.allocate_ui_with_layout(size, Layout::centered_and_justified(Direction::TopDown), |ui| {
ui.add(image);
});
Self::show_image_preview(ui, item, stored_images);
},
) as Box<dyn FnMut(&mut Ui, &InfoPanelEntry, &mut IndexSet<String>)>,
);
supported_images.insert(
"jpeg".to_string(),
Box::new(
|ui: &mut Ui, item: &InfoPanelEntry, stored_images: &mut IndexSet<String>| {
ui.label("Image");
stored_images.insert(format!("{}", item.directory_entry.as_path().display()));
let image = egui::Image::new(format!(
"file://{}",
item.directory_entry.as_path().display()
));
let size = Vec2 {
x: ui.available_width(),
y: ui.available_width() / 4.0 * 3.0,
};
ui.allocate_ui_with_layout(size, Layout::centered_and_justified(Direction::TopDown), |ui| {
ui.add(image);
});
Self::show_image_preview(ui, item, stored_images);
},
) as Box<dyn FnMut(&mut Ui, &InfoPanelEntry, &mut IndexSet<String>)>,
);
supported_images.insert(
"png".to_string(),
Box::new(
|ui: &mut Ui, item: &InfoPanelEntry, stored_images: &mut IndexSet<String>| {
ui.label("Image");
stored_images.insert(format!("{}", item.directory_entry.as_path().display()));
let image = egui::Image::new(format!(
"file://{}",
item.directory_entry.as_path().display()
));
let size = Vec2 {
x: ui.available_width(),
y: ui.available_width() / 4.0 * 3.0,
};
ui.allocate_ui_with_layout(size, Layout::centered_and_justified(Direction::TopDown), |ui| {
ui.add(image);
});
Self::show_image_preview(ui, item, stored_images);
},
) as Box<dyn FnMut(&mut Ui, &InfoPanelEntry, &mut IndexSet<String>)>,
);
Expand All @@ -211,6 +175,30 @@ impl Default for InformationPanel {
}

impl InformationPanel {
fn show_image_preview(
ui: &mut Ui,
item: &InfoPanelEntry,
stored_images: &mut IndexSet<String>,
) {
ui.label("Image");
stored_images.insert(format!("{}", item.directory_entry.as_path().display()));
let image = egui::Image::new(format!(
"file://{}",
item.directory_entry.as_path().display()
));
let size = Vec2 {
x: ui.available_width(),
y: ui.available_width() / 4.0 * 3.0,
};
ui.allocate_ui_with_layout(
size,
Layout::centered_and_justified(Direction::TopDown),
|ui| {
ui.add(image);
},
);
}

/// Adds support for previewing a custom file type.
///
/// # Arguments
Expand Down

0 comments on commit 4fdda5f

Please sign in to comment.