feat: add CompositeIcon struct for nesting SVGs

This commit is contained in:
2026-08-03 21:03:50 -04:00
parent d6dbfdf7ea
commit d0233b544d
4 changed files with 16 additions and 8 deletions
Generated
+7
View File
@@ -23,6 +23,12 @@ version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "base64"
version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b25655df2c3cdd83c5e5b293b88acd880332b2ddadd7c30ac43144fdc0033da9"
[[package]]
name = "bitflags"
version = "2.13.1"
@@ -402,6 +408,7 @@ name = "icon-color-tool"
version = "0.1.0"
dependencies = [
"anyhow",
"base64",
"gtk4",
"regex",
"serde",
+1
View File
@@ -10,3 +10,4 @@ regex = "1"
serde = { version = "1", features = ["derive"] }
toml = "0.8"
walkdir = "2"
base64 = "0.23.0"
+2 -1
View File
@@ -21,8 +21,9 @@ impl ColorScheme {
.with_context(|| format!("reading {}", path.display()))?;
if !namespace.is_empty() {
let class_re = Regex::new(r#"class=(['"])([^'"]*?)ColorScheme-([^'"]*?)(['"])"#).unwrap();
content = class_re.replace_all(&content, format!("class=${{1}}${{2}}{namespace}-ColorScheme-${{3}}${{4}}").as_str()).into_owned();
content = content.replace(".ColorScheme-", &format!(".{namespace}-ColorScheme-"));
content = content.replace("class=\"ColorScheme-", &format!("class=\"{namespace}-ColorScheme-"));
}
let colors = parse_colors(&content);
+6 -7
View File
@@ -25,16 +25,15 @@ impl CompositeIcon {
pub fn render(&self) -> String {
if let Some(emblem) = &self.emblem {
use base64::prelude::*;
let bg_b64 = BASE64_STANDARD.encode(&self.bg.content);
let emblem_b64 = BASE64_STANDARD.encode(&emblem.content);
format!(
r#"<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
<svg x="0" y="0" width="64" height="64" overflow="visible">
{}
</svg>
<svg x="{}" y="{}" width="{}" height="{}" overflow="visible">
{}
</svg>
<image x="0" y="0" width="64" height="64" href="data:image/svg+xml;base64,{}" />
<image x="{}" y="{}" width="{}" height="{}" href="data:image/svg+xml;base64,{}" />
</svg>"#,
self.bg.content, self.emblem_x, self.emblem_y, self.emblem_size, self.emblem_size, emblem.content
bg_b64, self.emblem_x, self.emblem_y, self.emblem_size, self.emblem_size, emblem_b64
)
} else {
self.bg.content.clone()