Using linicon crate for icons
Removed file
This commit is contained in:
committed by
nik012003
parent
ede183fdce
commit
26b1003bae
134
Cargo.lock
generated
134
Cargo.lock
generated
@@ -23,6 +23,12 @@ version = "1.0.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ahash"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ahash"
|
name = "ahash"
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
@@ -343,7 +349,7 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"crossbeam-utils",
|
"crossbeam-utils",
|
||||||
"memoffset",
|
"memoffset 0.7.1",
|
||||||
"scopeguard",
|
"scopeguard",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -461,6 +467,15 @@ dependencies = [
|
|||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dlv-list"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68df3f2b690c1b86e65ef7830956aededf3cb0a16f898f79b9a6f421a7b6211b"
|
||||||
|
dependencies = [
|
||||||
|
"rand 0.8.5",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.8.0"
|
version = "1.8.0"
|
||||||
@@ -522,6 +537,15 @@ dependencies = [
|
|||||||
"color-maps",
|
"color-maps",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "file-locker"
|
||||||
|
version = "1.1.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e91c8a37357ab5d51f1a8053900fe8374283449695c5418b66f45deece50705f"
|
||||||
|
dependencies = [
|
||||||
|
"nix 0.25.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "flagset"
|
name = "flagset"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
@@ -602,6 +626,16 @@ dependencies = [
|
|||||||
"ttf-parser",
|
"ttf-parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "freedesktop_entry_parser"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "db9c27b72f19a99a895f8ca89e2d26e4ef31013376e56fdafef697627306c3e4"
|
||||||
|
dependencies = [
|
||||||
|
"nom",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fuchsia-cprng"
|
name = "fuchsia-cprng"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@@ -683,6 +717,15 @@ dependencies = [
|
|||||||
"crunchy",
|
"crunchy",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hashbrown"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
|
||||||
|
dependencies = [
|
||||||
|
"ahash 0.4.7",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heck"
|
name = "heck"
|
||||||
version = "0.4.0"
|
version = "0.4.0"
|
||||||
@@ -838,6 +881,29 @@ version = "0.2.138"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linicon"
|
||||||
|
version = "2.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4ee8c5653188a809616c97296180a0547a61dba205bcdcbdd261dbd022a25fd9"
|
||||||
|
dependencies = [
|
||||||
|
"file-locker",
|
||||||
|
"freedesktop_entry_parser",
|
||||||
|
"linicon-theme",
|
||||||
|
"memmap2",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linicon-theme"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a4f8240c33bb08c5d8b8cdea87b683b05e61037aa76ff26bef40672cc6ecbb80"
|
||||||
|
dependencies = [
|
||||||
|
"freedesktop_entry_parser",
|
||||||
|
"rust-ini",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "link-cplusplus"
|
name = "link-cplusplus"
|
||||||
version = "1.0.7"
|
version = "1.0.7"
|
||||||
@@ -908,6 +974,15 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.6.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "memoffset"
|
name = "memoffset"
|
||||||
version = "0.7.1"
|
version = "0.7.1"
|
||||||
@@ -917,6 +992,12 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minimal-lexical"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "miniz_oxide"
|
name = "miniz_oxide"
|
||||||
version = "0.5.4"
|
version = "0.5.4"
|
||||||
@@ -974,6 +1055,20 @@ dependencies = [
|
|||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nix"
|
||||||
|
version = "0.25.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"bitflags",
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"memoffset 0.6.5",
|
||||||
|
"pin-utils",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nix"
|
name = "nix"
|
||||||
version = "0.26.1"
|
version = "0.26.1"
|
||||||
@@ -983,11 +1078,21 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"memoffset",
|
"memoffset 0.7.1",
|
||||||
"pin-utils",
|
"pin-utils",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "nom"
|
||||||
|
version = "7.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
"minimal-lexical",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu-ansi-term"
|
name = "nu-ansi-term"
|
||||||
version = "0.46.0"
|
version = "0.46.0"
|
||||||
@@ -1074,6 +1179,16 @@ version = "1.16.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ordered-multimap"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1c672c7ad9ec066e428c00eb917124a06f08db19e2584de982cc34b1f4c12485"
|
||||||
|
dependencies = [
|
||||||
|
"dlv-list",
|
||||||
|
"hashbrown",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "os_str_bytes"
|
name = "os_str_bytes"
|
||||||
version = "6.4.1"
|
version = "6.4.1"
|
||||||
@@ -1275,9 +1390,10 @@ dependencies = [
|
|||||||
"glam",
|
"glam",
|
||||||
"image",
|
"image",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"linicon",
|
||||||
"manifest-dir-macros",
|
"manifest-dir-macros",
|
||||||
"mint",
|
"mint",
|
||||||
"nix",
|
"nix 0.26.1",
|
||||||
"resvg",
|
"resvg",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
"sha2",
|
"sha2",
|
||||||
@@ -1484,6 +1600,16 @@ dependencies = [
|
|||||||
"xmlparser",
|
"xmlparser",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rust-ini"
|
||||||
|
version = "0.17.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "63471c4aa97a1cf8332a5f97709a79a4234698de6a1f5087faf66f2dae810e22"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"ordered-multimap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.21"
|
version = "0.1.21"
|
||||||
@@ -2069,7 +2195,7 @@ version = "0.9.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "371436099f2980de56dc385b615696d3eabbdac9649a72b85f9d75f68474fa9c"
|
checksum = "371436099f2980de56dc385b615696d3eabbdac9649a72b85f9d75f68474fa9c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash 0.7.6",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"parking_lot 0.11.2",
|
"parking_lot 0.11.2",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ ez-pixmap = "0.2.2"
|
|||||||
glam = { version = "0.22.0", features = ["mint"] }
|
glam = { version = "0.22.0", features = ["mint"] }
|
||||||
image = "0.24.5"
|
image = "0.24.5"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
|
linicon = "2.3.0"
|
||||||
manifest-dir-macros = "0.1.16"
|
manifest-dir-macros = "0.1.16"
|
||||||
mint = "0.5.9"
|
mint = "0.5.9"
|
||||||
nix = "0.26.1"
|
nix = "0.26.1"
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ use tween::{QuartInOut, Tweener};
|
|||||||
use ustr::ustr;
|
use ustr::ustr;
|
||||||
|
|
||||||
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
||||||
let model = match icon {
|
return match &icon.icon_type {
|
||||||
Icon::Png(path) => {
|
RawIconType::Png(path) => {
|
||||||
let model = Model::create(
|
let model = Model::create(
|
||||||
parent,
|
parent,
|
||||||
Transform::from_rotation(Quat::from_rotation_y(PI)),
|
Transform::from_rotation(Quat::from_rotation_y(PI)),
|
||||||
@@ -32,15 +32,15 @@ fn model_from_icon(parent: &Spatial, icon: &Icon) -> Result<Model> {
|
|||||||
"diffuse",
|
"diffuse",
|
||||||
MaterialParameter::Texture(ResourceID::Direct(path.clone())),
|
MaterialParameter::Texture(ResourceID::Direct(path.clone())),
|
||||||
)?;
|
)?;
|
||||||
model
|
Ok(model)
|
||||||
}
|
}
|
||||||
Icon::Gltf(path) => Model::create(
|
RawIconType::Gltf(path) => Ok(Model::create(
|
||||||
parent,
|
parent,
|
||||||
Transform::from_scale([0.05; 3]),
|
Transform::from_scale([0.05; 3]),
|
||||||
&ResourceID::new_direct(path)?,
|
&ResourceID::new_direct(path)?,
|
||||||
)?,
|
)?),
|
||||||
|
_ => panic!("asd"),
|
||||||
};
|
};
|
||||||
Ok(model)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ProtoStar {
|
pub struct ProtoStar {
|
||||||
@@ -54,11 +54,12 @@ pub struct ProtoStar {
|
|||||||
impl ProtoStar {
|
impl ProtoStar {
|
||||||
pub fn create_from_desktop_file(parent: &Spatial, desktop_file: DesktopFile) -> Result<Self> {
|
pub fn create_from_desktop_file(parent: &Spatial, desktop_file: DesktopFile) -> Result<Self> {
|
||||||
// dbg!(&desktop_file);
|
// dbg!(&desktop_file);
|
||||||
let mut raw_icons = desktop_file.get_raw_icons();
|
dbg!(&desktop_file);
|
||||||
|
let mut raw_icons = dbg!(desktop_file.get_raw_icons());
|
||||||
let last_icon = raw_icons.pop();
|
let last_icon = raw_icons.pop();
|
||||||
let icon = raw_icons
|
let icon = raw_icons
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.find(|i| match i {
|
.find(|i| match i.icon_type {
|
||||||
RawIconType::Png(_) => false,
|
RawIconType::Png(_) => false,
|
||||||
RawIconType::Svg(_) => false,
|
RawIconType::Svg(_) => false,
|
||||||
RawIconType::Gltf(_) => true,
|
RawIconType::Gltf(_) => true,
|
||||||
@@ -77,7 +78,7 @@ impl ProtoStar {
|
|||||||
parent,
|
parent,
|
||||||
Transform::default(),
|
Transform::default(),
|
||||||
match icon.as_ref() {
|
match icon.as_ref() {
|
||||||
Some(Icon::Png(_)) => [0.05, 0.0665, 0.005],
|
Some(_) => [0.05, 0.0665, 0.005],
|
||||||
_ => [0.05; 3],
|
_ => [0.05; 3],
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
|
|||||||
96
src/xdg.rs
96
src/xdg.rs
@@ -10,8 +10,7 @@ use std::str::FromStr;
|
|||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use sha2::{Sha224, Digest};
|
use sha2::{Sha224, Digest};
|
||||||
|
use linicon;
|
||||||
const ICON_SIZES: &[&str] = &["64x64", "32x32", "scalable", "128x128"];
|
|
||||||
|
|
||||||
fn get_data_dirs() -> Vec<PathBuf> {
|
fn get_data_dirs() -> Vec<PathBuf> {
|
||||||
let xdg_data_dirs_str = std::env::var("XDG_DATA_DIRS")
|
let xdg_data_dirs_str = std::env::var("XDG_DATA_DIRS")
|
||||||
@@ -108,7 +107,7 @@ pub fn parse_desktop_file(path: PathBuf) -> Result<DesktopFile, String> {
|
|||||||
Some((key, value)) => (key, value),
|
Some((key, value)) => (key, value),
|
||||||
None => continue,
|
None => continue,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Parse the key-value pair based on the key
|
// Parse the key-value pair based on the key
|
||||||
match key {
|
match key {
|
||||||
"Name" => name = Some(value.to_string()),
|
"Name" => name = Some(value.to_string()),
|
||||||
@@ -171,71 +170,54 @@ pub struct DesktopFile {
|
|||||||
pub no_display: bool,
|
pub no_display: bool,
|
||||||
}
|
}
|
||||||
impl DesktopFile {
|
impl DesktopFile {
|
||||||
pub fn get_raw_icons(&self) -> Vec<RawIconType> {
|
pub fn get_raw_icons(&self) -> Vec<Icon> {
|
||||||
// Get the name of the icon from the DesktopFile struct
|
// Get the name of the icon from the DesktopFile struct
|
||||||
let Some(icon_name) = self.icon.as_ref() else { return Vec::new(); };
|
let Some(icon_name) = self.icon.as_ref() else { return Vec::new(); };
|
||||||
let test_icon_path = self.path.join(Path::new(icon_name));
|
let test_icon_path = self.path.join(Path::new(icon_name));
|
||||||
if test_icon_path.exists() {
|
if test_icon_path.exists() {
|
||||||
return RawIconType::from_path(test_icon_path)
|
if let Some(icon) = Icon::from_path(test_icon_path,128) {
|
||||||
.map(|i| vec![i])
|
return vec![icon]
|
||||||
.unwrap_or_default();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let Ok(icon_name) = OsString::from_str(icon_name) else { return Vec::new(); };
|
let mut icons_iter= linicon::lookup_icon(icon_name);
|
||||||
|
|
||||||
// Get the current icon theme from the XDG_ICON_THEME environment variable, or use "hicolor" as the default theme if the variable is not defined
|
let sized_png : Vec<Icon> = icons_iter
|
||||||
let icon_theme = env::var_os("XDG_ICON_THEME").unwrap_or("hicolor".into());
|
.filter_map(|i| i.ok())
|
||||||
|
.filter(|i| i.icon_type != linicon::IconType::XMP) //TODO: support XMP
|
||||||
// Get the XDG_DATA_HOME and XDG_DATA_DIRS environment variables, and split the XDG_DATA_DIRS variable into a list of directories
|
.map(|i| Icon::from_path(i.path,i.max_size - 2 ).unwrap())
|
||||||
let xdg_data_dirs = get_data_dirs();
|
.collect();
|
||||||
|
sized_png
|
||||||
// Concatenate the XDG_DATA_HOME and XDG_DATA_DIRS directories with the default path for icon themes
|
|
||||||
xdg_data_dirs // XDG_DATA_DIRS directories
|
|
||||||
.into_iter()
|
|
||||||
.flat_map(|dir| {
|
|
||||||
let icons_path = dir.join("icons").join(&icon_theme);
|
|
||||||
ICON_SIZES
|
|
||||||
.iter()
|
|
||||||
.map(|path| icons_path.join(path).join("apps"))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
})
|
|
||||||
.filter_map(|dir| {
|
|
||||||
let dir = fs::read_dir(dir).ok()?;
|
|
||||||
Some(
|
|
||||||
dir.filter_map(|e| e.ok())
|
|
||||||
.map(|file| file.path())
|
|
||||||
.filter(|file| file.file_stem() == Some(&icon_name)),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
.flatten()
|
|
||||||
.filter_map(RawIconType::from_path)
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct Icon {
|
||||||
|
pub icon_type: RawIconType,
|
||||||
|
pub size: u16,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub enum RawIconType {
|
pub enum RawIconType {
|
||||||
Png(PathBuf),
|
Png(PathBuf),
|
||||||
Svg(PathBuf),
|
Svg(PathBuf),
|
||||||
Gltf(PathBuf),
|
Gltf(PathBuf),
|
||||||
}
|
}
|
||||||
impl RawIconType {
|
impl Icon {
|
||||||
pub fn from_path(path: PathBuf) -> Option<RawIconType> {
|
pub fn from_path(path: PathBuf, size: u16) -> Option<Icon>{
|
||||||
match path.extension().and_then(|ext| ext.to_str()) {
|
let icon_type = match path.extension().and_then(|ext| ext.to_str()) {
|
||||||
Some("png") => Some(RawIconType::Png(path)),
|
Some("png") => Some(RawIconType::Png(path)),
|
||||||
Some("svg") => Some(RawIconType::Svg(path)),
|
Some("svg") => Some(RawIconType::Svg(path)),
|
||||||
Some("glb") | Some("gltf") => Some(RawIconType::Gltf(path)),
|
Some("glb") | Some("gltf") => Some(RawIconType::Gltf(path)),
|
||||||
_ => None,
|
_ => {return None},
|
||||||
}
|
}.unwrap();
|
||||||
|
return Some(Icon{icon_type,size})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process(self, size: u32) -> Result<Icon, std::io::Error> {
|
pub fn process(self, size: u16) -> Result<Icon, std::io::Error> {
|
||||||
match self {
|
match self.icon_type {
|
||||||
RawIconType::Png(path) => Ok(Icon::Png(path)),
|
RawIconType::Svg(path) => Ok(Icon::from_path(get_png_from_svg(&path, size)?,size).unwrap()),
|
||||||
RawIconType::Svg(path) => {
|
_ => Ok(self),
|
||||||
Ok(Icon::Png(get_png_from_svg(&path, size)?))
|
|
||||||
}
|
|
||||||
RawIconType::Gltf(path) => Ok(Icon::Gltf(path)),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -257,18 +239,10 @@ fn test_get_icon_path() {
|
|||||||
dbg!(&icon_paths);
|
dbg!(&icon_paths);
|
||||||
|
|
||||||
// Assert that the get_icon_path() function returns the expected result
|
// Assert that the get_icon_path() function returns the expected result
|
||||||
assert!(icon_paths.contains(&RawIconType::Png(PathBuf::from(
|
assert!(icon_paths.contains(&Icon::from_path(PathBuf::from("/usr/share/icons/hicolor/32x32/apps/krita.png"),32).unwrap()));
|
||||||
"/usr/share/icons/hicolor/32x32/apps/krita.png"
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
pub fn get_png_from_svg(svg_path: impl AsRef<Path>, size: u16,) -> Result<PathBuf, std::io::Error> {
|
||||||
pub enum Icon {
|
|
||||||
Png(PathBuf),
|
|
||||||
Gltf(PathBuf),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_png_from_svg(svg_path: impl AsRef<Path>, size: u32,) -> Result<PathBuf, std::io::Error> {
|
|
||||||
let svg_path = fs::canonicalize(svg_path)?;
|
let svg_path = fs::canonicalize(svg_path)?;
|
||||||
let tree = Tree::from_data(
|
let tree = Tree::from_data(
|
||||||
fs::read(svg_path.as_path())?.as_slice(),
|
fs::read(svg_path.as_path())?.as_slice(),
|
||||||
@@ -303,10 +277,10 @@ pub fn get_png_from_svg(svg_path: impl AsRef<Path>, size: u32,) -> Result<PathBu
|
|||||||
return Ok(png_path)
|
return Ok(png_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut pixmap = Pixmap::new(size, size).unwrap();
|
let mut pixmap = Pixmap::new(size.into(), size.into()).unwrap();
|
||||||
render(
|
render(
|
||||||
&tree,
|
&tree,
|
||||||
FitTo::Width(size),
|
FitTo::Width(size.into()),
|
||||||
Transform::identity(),
|
Transform::identity(),
|
||||||
pixmap.as_mut(),
|
pixmap.as_mut(),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user