Skip to content

Commit

Permalink
cut uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeWaka committed Sep 11, 2023
1 parent 206e886 commit 9633fcd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 67 deletions.
61 changes: 0 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ log = "0.4"
lazy_static = "1.4.0"
once_cell = "1.18.0"
rfd = "0.12.0"
uuid = { version = "1.4.1", features = ["js", "fast-rng", "v4"] }

# You only need serde if you want app persistence:
#serde = { version = "1", features = ["derive"] }
Expand Down
18 changes: 15 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ use crate::{
use egui::{mutex::Mutex, Align2, DroppedFile, FontId, RichText, TextStyle};
use egui_extras::{image::load_image_bytes, RetainedImage};

use std::{cell::RefCell, io::Cursor, rc::Rc};
use std::{
cell::RefCell,
collections::hash_map::DefaultHasher,
hash::{Hash, Hasher},
io::Cursor,
rc::Rc,
};

#[derive(Default)]
pub struct MetadataTool {
Expand Down Expand Up @@ -111,6 +117,7 @@ impl MetadataTool {

pub fn load_files_or_err(&mut self, ui: &mut egui::Ui) {
if !self.dropped_files.is_empty() {
let mut hasher = DefaultHasher::new();
ui.group(|ui| {
for file in &self.dropped_files {
if let Some(bytes) = Self::load_file_contents(file) {
Expand Down Expand Up @@ -138,7 +145,12 @@ impl MetadataTool {

if let Ok(raw_dmi) = dmi::RawDmi::load(bytes_reader) {
let new_mwin = ImageWindow {
id: uuid::Uuid::new_v4(),
id: {
for chunk in &raw_dmi.chunks_idat {
chunk.data.hash(&mut hasher)
}
hasher.finish().to_string().into()
},
img: {
let h = (ui.available_height() * 1.85) as u32;
let w = (ui.available_width() * 1.85) as u32;
Expand Down Expand Up @@ -190,7 +202,7 @@ impl eframe::App for MetadataTool {

for mwindow in &self.windows {
egui::Window::new(&mwindow.metadata.file_name)
.id(mwindow.id.to_string().into())
.id(mwindow.id)
.open(&mut mwindow.is_open.borrow_mut())
.show(ctx, |ui| {
create_meta_viewer(mwindow, ui, &mwindow.metadata, &tst);
Expand Down
4 changes: 2 additions & 2 deletions src/image_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use poll_promise::Promise;
use std::{cell::RefCell, rc::Rc};

pub struct ImageWindow {
pub id: uuid::Uuid,
pub id: egui::Id,
pub img: Rc<RetainedImage>,
pub dmi: dmi::RawDmi,
pub metadata: Rc<ImageMetadata>,
Expand All @@ -26,7 +26,7 @@ pub fn create_meta_viewer(
metadata: &Rc<ImageMetadata>,
toasts: &RefCell<&mut Toasts>,
) {
egui::TopBottomPanel::bottom(format!("{}_meta", img_win.id)).show_inside(ui, |ui| {
egui::TopBottomPanel::bottom(format!("{:?}_meta", img_win.id)).show_inside(ui, |ui| {
ui.add_space(6.0);
ui.allocate_ui_with_layout(
vec2(ui.available_width(), ui.available_height()),
Expand Down

0 comments on commit 9633fcd

Please sign in to comment.