-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial implementation of file information display
- Loading branch information
Showing
8 changed files
with
257 additions
and
9 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
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
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
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
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
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,43 @@ | ||
use image::RgbaImage; | ||
|
||
#[derive(Debug, Default)] | ||
pub struct MetaData { | ||
pub file_name: String, | ||
pub dimensions: Option<(usize, usize)>, | ||
pub scaled_dimensions: Option<(usize, usize)>, | ||
pub preview_image_bytes: Option<RgbaImage>, | ||
pub preview_text: Option<String>, | ||
pub file_size: Option<String>, | ||
pub file_type: Option<String>, | ||
pub file_modified: Option<String>, | ||
pub file_created: Option<String>, | ||
} | ||
|
||
pub fn format_bytes(bytes: u64) -> String { | ||
const KB: u64 = 1024; | ||
const MB: u64 = KB * 1024; | ||
const GB: u64 = MB * 1024; | ||
const TB: u64 = GB * 1024; | ||
|
||
if bytes >= TB { | ||
format!("{:.2} TB", bytes as f64 / TB as f64) | ||
} else if bytes >= GB { | ||
format!("{:.2} GB", bytes as f64 / GB as f64) | ||
} else if bytes >= MB { | ||
format!("{:.2} MB", bytes as f64 / MB as f64) | ||
} else if bytes >= KB { | ||
format!("{:.2} KB", bytes as f64 / KB as f64) | ||
} else { | ||
format!("{} B", bytes) | ||
} | ||
} | ||
|
||
pub fn format_pixels(pixels: usize) -> String { | ||
const K: usize = 1_000; | ||
const M: usize = K * 1_000; | ||
if pixels >= K { | ||
format!("{:.2} MPx", pixels as f64 / M as f64) | ||
} else { | ||
format!("{} Px", pixels) | ||
} | ||
} |
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
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