-
Notifications
You must be signed in to change notification settings - Fork 13
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 1 commit
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
+29
to
+30
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 Consider using a logging crate instead of Using |
||
| } | ||
|
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>, | ||
|
|
||
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.
💡 Codebase verification
Action Required: Update
rust-embedto the Latest VersionThe current dependency version
rust-embed = "6.4.0"is outdated. The latest version available is8.5.0, which includes important bug fixes and enhancements. Please consider updating to the latest version to ensure optimal performance and security.🔗 Analysis chain
Approved: Addition of rust-embed dependency.
The addition of the
rust-embeddependency aligns well with the PR objectives of fixing broken images in the binary. This should allow for embedding icon assets directly into the application, potentially resolving the issue with loading icons and images for the sidebar.Consider the following suggestions:
rust-embed. If not, consider updating to the latest stable version, unless there's a specific reason to use this version.Cargo.tomlfile, rather than adding it at the end.Let's check if there's a newer version of
rust-embedavailable:This will help ensure we're using the most up-to-date version of the library.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 85