Skip to content

Commit

Permalink
Merge pull request #10 from dashpay/fix-icon-loading
Browse files Browse the repository at this point in the history
fix: broken images in binary
  • Loading branch information
ktechmidas authored Oct 20, 2024
2 parents 924b51d + f455ba0 commit 5e9f3be
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ serde_yaml = "0.9.34+deprecated"
image = { version = "0.25.2", default-features = false, features = ["png"] }
bitflags = "2.6.0"
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
rust-embed = "8.5.0"
45 changes: 29 additions & 16 deletions src/ui/components/left_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
} 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>,
Expand All @@ -34,27 +47,27 @@ pub fn add_left_panel(
(
"I",
RootScreenType::RootScreenIdentities,
"icons/identity.png",
"identity.png",
),
(
"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",
),
];

Expand Down

0 comments on commit 5e9f3be

Please sign in to comment.