Convert standalone_icons to a map

This commit is contained in:
Ridan Vandenbergh 2025-06-21 13:27:17 +02:00
parent 79dbfa3c09
commit 15e73777a1
No known key found for this signature in database
2 changed files with 11 additions and 5 deletions

View file

@ -259,9 +259,17 @@ impl IconLocations {
pub fn icons(self) -> Icons {
let themes = self.resolve();
let standalone_icons = self.standalone_icons
.into_iter()
.map(|file| {
let key = file.path.file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or(String::new());
(key, file)
})
.collect();
Icons {
standalone_icons: self.standalone_icons,
standalone_icons,
themes,
}
}

View file

@ -20,7 +20,7 @@ use std::sync::Arc;
/// Icons::new().find_icon("firefox", 32, 1, "hicolor");
/// ```
pub struct Icons {
pub standalone_icons: Vec<IconFile>,
pub standalone_icons: HashMap<String, IconFile>,
pub themes: HashMap<OsString, Arc<Theme>>,
}
@ -82,9 +82,7 @@ impl Icons {
///
/// These icons do not have any size or scalability information attached to them.
pub fn find_standalone_icon(&self, icon_name: &str) -> Option<IconFile> {
self.standalone_icons
.iter()
.find(|ico| ico.path.file_stem() == Some(icon_name.as_ref()))
self.standalone_icons.get(icon_name)
.cloned()
}
}