mirror of
https://github.com/danbulant/icon
synced 2026-06-24 17:11:58 +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 {
|
pub fn icons(self) -> Icons {
|
||||||
let themes = self.resolve();
|
let themes = self.resolve();
|
||||||
|
|
||||||
let standalone_icons = self.standalone_icons
|
let standalone_icons = self
|
||||||
|
.standalone_icons
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|file| {
|
.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)
|
(key, file)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
@ -388,18 +393,17 @@ impl IconLocations {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
if !chain.contains(&parent_idx) {
|
// add this parent, removing any previous occurrences
|
||||||
chain.push(parent_idx);
|
chain.retain(|idx| *idx != parent_idx);
|
||||||
}
|
chain.push(parent_idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// From the spec: "If no theme is specified, implementations are required to add the
|
// From the spec: "If no theme is specified, implementations are required to add the
|
||||||
// "hicolor" theme to the inheritance tree."
|
// "hicolor" theme to the inheritance tree."
|
||||||
if let Some(hicolor_idx) = hicolor_idx {
|
if let Some(hicolor_idx) = hicolor_idx {
|
||||||
if !chain.contains(&hicolor_idx) {
|
chain.retain(|idx| *idx != hicolor_idx);
|
||||||
chain.push(hicolor_idx);
|
chain.push(hicolor_idx);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
theme_chains.push(chain);
|
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.
|
/// - If the icon is not found in any of the themes, the standalone icon list is checked.
|
||||||
///
|
///
|
||||||
/// # Icon matching
|
/// # Icon matching
|
||||||
///
|
///
|
||||||
/// This function will return an icon matching the specified size and scale exactly if it exists.
|
/// 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.
|
/// 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
|
/// 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.
|
/// and its parents, and no standalone icon by the same name exists either.
|
||||||
///
|
///
|
||||||
pub fn find_icon(
|
pub fn find_icon(
|
||||||
&self,
|
&self,
|
||||||
icon_name: &str,
|
icon_name: &str,
|
||||||
|
|
@ -68,7 +68,7 @@ impl Icons {
|
||||||
if icon_name.is_empty() {
|
if icon_name.is_empty() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let theme = self.theme(theme).or_else(|| self.theme("hicolor"))?;
|
let theme = self.theme(theme).or_else(|| self.theme("hicolor"))?;
|
||||||
theme
|
theme
|
||||||
.find_icon(icon_name, size, scale)
|
.find_icon(icon_name, size, scale)
|
||||||
|
|
@ -76,14 +76,13 @@ impl Icons {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Look up a standalone icon by name.
|
/// Look up a standalone icon by name.
|
||||||
///
|
///
|
||||||
/// "Standalone" icons are icons that live outside icon themes, residing at the root in the
|
/// "Standalone" icons are icons that live outside icon themes, residing at the root in the
|
||||||
/// search directories instead.
|
/// 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> {
|
pub fn find_standalone_icon(&self, icon_name: &str) -> Option<IconFile> {
|
||||||
self.standalone_icons.get(icon_name)
|
self.standalone_icons.get(icon_name).cloned()
|
||||||
.cloned()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue