-
Notifications
You must be signed in to change notification settings - Fork 12
fix: broken images in binary #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,24 +4,37 @@ use crate::ui::RootScreenType; | |
| use eframe::epaint::{Color32, Margin}; | ||
| use egui::{Context, Frame, ImageButton, SidePanel, TextureHandle}; | ||
| use std::sync::Arc; | ||
| use rust_embed::RustEmbed; | ||
|
|
||
| // Function to load an icon as a texture | ||
| #[derive(RustEmbed)] | ||
| #[folder = "icons/"] // Adjust the folder path if necessary | ||
| struct Assets; | ||
|
|
||
| // Function to load an icon as a texture using embedded assets | ||
| fn load_icon(ctx: &Context, path: &str) -> Option<TextureHandle> { | ||
| if let Ok(image) = image::open(path) { | ||
| let size = [image.width() as usize, image.height() as usize]; | ||
| let rgba_image = image.into_rgba8(); | ||
| let pixels = rgba_image.into_raw(); | ||
| // Attempt to retrieve the embedded file | ||
| if let Some(content) = Assets::get(path) { | ||
| // Load the image from the embedded bytes | ||
| if let Ok(image) = image::load_from_memory(&content.data) { | ||
| let size = [image.width() as usize, image.height() as usize]; | ||
| let rgba_image = image.into_rgba8(); | ||
| let pixels = rgba_image.into_raw(); | ||
|
|
||
| Some(ctx.load_texture( | ||
| path, | ||
| egui::ColorImage::from_rgba_unmultiplied(size, &pixels), | ||
| Default::default(), | ||
| )) | ||
| Some(ctx.load_texture( | ||
| path, | ||
| egui::ColorImage::from_rgba_unmultiplied(size, &pixels), | ||
| Default::default(), | ||
| )) | ||
| } else { | ||
| eprintln!("Failed to load image from embedded data at path: {}", path); | ||
| None | ||
| } | ||
|
Comment on lines
+16
to
+31
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Simplify nested The nested Here's an example of how you might refactor it: fn load_icon(ctx: &Context, path: &str) -> Option<TextureHandle> {
Assets::get(path).and_then(|content| {
image::load_from_memory(&content.data).ok().map(|image| {
let size = [image.width() as usize, image.height() as usize];
let rgba_image = image.into_rgba8();
let pixels = rgba_image.into_raw();
ctx.load_texture(
path,
egui::ColorImage::from_rgba_unmultiplied(size, &pixels),
Default::default(),
)
})
})
} |
||
| } else { | ||
| eprintln!("Failed to load icon at path: {}", path); | ||
| eprintln!("Image not found in embedded assets at path: {}", path); | ||
| None | ||
| } | ||
| } | ||
|
|
||
| pub fn add_left_panel( | ||
| ctx: &Context, | ||
| app_context: &Arc<AppContext>, | ||
|
|
@@ -34,27 +47,27 @@ pub fn add_left_panel( | |
| ( | ||
| "I", | ||
| RootScreenType::RootScreenIdentities, | ||
| "icons/identity.png", | ||
| "identity.png", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix inconsistent icon path. The icon paths have been updated to remove the "icons/" prefix, which is correct for the new embedded asset approach. However, there's an inconsistency in one of the paths: "icons/tools.png", // Line 65This path still includes the "icons/" prefix, while others don't. To maintain consistency and ensure all icons load correctly, update this line to: "tools.png",This change will align all icon paths with the new embedded asset structure. Also applies to: 55-55, 60-60, 65-65, 70-70 |
||
| ), | ||
| ( | ||
| "C", | ||
| RootScreenType::RootScreenDPNSContestedNames, | ||
| "icons/voting.png", | ||
| "voting.png", | ||
| ), | ||
| ( | ||
| "Q", | ||
| RootScreenType::RootScreenDocumentQuery, | ||
| "icons/doc.png", | ||
| "doc.png", | ||
| ), | ||
| ( | ||
| "T", | ||
| RootScreenType::RootScreenTransitionVisualizerScreen, | ||
| "icons/tools.png", | ||
| "tools.png", | ||
| ), | ||
| ( | ||
| "N", | ||
| RootScreenType::RootScreenNetworkChooser, | ||
| "icons/config.png", | ||
| "config.png", | ||
| ), | ||
| ]; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider using a logging crate instead of
eprintln!Using
eprintln!for error messages in a GUI application may not be ideal. Consider using a logging crate likelogorenv_loggerfor more flexible and configurable logging, which can be directed to files, consoles, or other outputs as needed.