From 3b4e258225c9e3762ab8f15594d3f44a9f1693ac Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sun, 20 Oct 2024 11:54:12 +0300 Subject: [PATCH 1/5] fix: broken images in binary --- Cargo.toml | 1 + src/ui/components/left_panel.rs | 35 ++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8cecc62e..492dcc76 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "6.4.0" \ No newline at end of file diff --git a/src/ui/components/left_panel.rs b/src/ui/components/left_panel.rs index 2f89e17b..fc5a9ac6 100644 --- a/src/ui/components/left_panel.rs +++ b/src/ui/components/left_panel.rs @@ -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 { - 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, From 479e0306a4ee5dfeceeabc0555726a27a375b2df Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sun, 20 Oct 2024 12:55:59 +0300 Subject: [PATCH 2/5] fix paths --- src/ui/components/left_panel.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ui/components/left_panel.rs b/src/ui/components/left_panel.rs index fc5a9ac6..f1f0fd50 100644 --- a/src/ui/components/left_panel.rs +++ b/src/ui/components/left_panel.rs @@ -47,17 +47,17 @@ 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", @@ -67,7 +67,7 @@ pub fn add_left_panel( ( "N", RootScreenType::RootScreenNetworkChooser, - "icons/config.png", + "config.png", ), ]; From 28dbd67f73a03378d0d3b9659d7a1570008a227f Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sun, 20 Oct 2024 12:59:49 +0300 Subject: [PATCH 3/5] missed one --- src/ui/components/left_panel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/components/left_panel.rs b/src/ui/components/left_panel.rs index f1f0fd50..f3c01abd 100644 --- a/src/ui/components/left_panel.rs +++ b/src/ui/components/left_panel.rs @@ -62,7 +62,7 @@ pub fn add_left_panel( ( "T", RootScreenType::RootScreenTransitionVisualizerScreen, - "icons/tools.png", + "tools.png", ), ( "N", From e843764268160c4d9ad0dff492e129e067a15c10 Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:08:22 +0300 Subject: [PATCH 4/5] update dep to latest --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 492dcc76..7d23885f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,4 +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 = "6.4.0" \ No newline at end of file +rust-embed = "8.5.0" \ No newline at end of file From f455ba0b2b20eae2518b6570d890727c743588e8 Mon Sep 17 00:00:00 2001 From: ktechmidas <9920871+ktechmidas@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:08:54 +0300 Subject: [PATCH 5/5] newline --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7d23885f..b28b11db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,4 +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" \ No newline at end of file +rust-embed = "8.5.0"