mirror of
https://github.com/danbulant/icon
synced 2026-05-19 04:08:36 +00:00
Fix issue where hicolor may not end up last in chain
This commit is contained in:
parent
cfc932cd8e
commit
0bc75d5ef5
2 changed files with 21 additions and 18 deletions
|
|
@ -259,11 +259,16 @@ impl IconLocations {
|
|||
|
||||
pub fn icons(self) -> Icons {
|
||||
let themes = self.resolve();
|
||||
|
||||
let standalone_icons = self.standalone_icons
|
||||
|
||||
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());
|
||||
let key = file
|
||||
.path
|
||||
.file_stem()
|
||||
.map(|s| s.to_string_lossy().to_string())
|
||||
.unwrap_or(String::new());
|
||||
(key, file)
|
||||
})
|
||||
.collect();
|
||||
|
|
@ -388,18 +393,17 @@ impl IconLocations {
|
|||
continue;
|
||||
};
|
||||
|
||||
if !chain.contains(&parent_idx) {
|
||||
chain.push(parent_idx);
|
||||
}
|
||||
// add this parent, removing any previous occurrences
|
||||
chain.retain(|idx| *idx != parent_idx);
|
||||
chain.push(parent_idx);
|
||||
}
|
||||
}
|
||||
|
||||
// From the spec: "If no theme is specified, implementations are required to add the
|
||||
// "hicolor" theme to the inheritance tree."
|
||||
if let Some(hicolor_idx) = hicolor_idx {
|
||||
if !chain.contains(&hicolor_idx) {
|
||||
chain.push(hicolor_idx);
|
||||
}
|
||||
chain.retain(|idx| *idx != hicolor_idx);
|
||||
chain.push(hicolor_idx);
|
||||
}
|
||||
|
||||
theme_chains.push(chain);
|
||||
|
|
|
|||
17
src/theme.rs
17
src/theme.rs
|
|
@ -51,13 +51,13 @@ impl Icons {
|
|||
/// - If the icon is not found in any of the themes, the standalone icon list is checked.
|
||||
///
|
||||
/// # Icon matching
|
||||
///
|
||||
///
|
||||
/// This function will return an icon matching the specified size and scale exactly if it exists.
|
||||
/// Otherwise, an icon with the smallest "distance" (in icon size) is returned.
|
||||
///
|
||||
///
|
||||
/// This will only return `None` if no icon by the specified name exists in the specified theme
|
||||
/// and its parents, and no standalone icon by the same name exists either.
|
||||
///
|
||||
///
|
||||
pub fn find_icon(
|
||||
&self,
|
||||
icon_name: &str,
|
||||
|
|
@ -68,7 +68,7 @@ impl Icons {
|
|||
if icon_name.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
let theme = self.theme(theme).or_else(|| self.theme("hicolor"))?;
|
||||
theme
|
||||
.find_icon(icon_name, size, scale)
|
||||
|
|
@ -76,14 +76,13 @@ impl Icons {
|
|||
}
|
||||
|
||||
/// Look up a standalone icon by name.
|
||||
///
|
||||
///
|
||||
/// "Standalone" icons are icons that live outside icon themes, residing at the root in the
|
||||
/// search directories instead.
|
||||
///
|
||||
/// These icons do not have any size or scalability information attached to them.
|
||||
///
|
||||
/// 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.get(icon_name)
|
||||
.cloned()
|
||||
self.standalone_icons.get(icon_name).cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue