feat: add ability to provide extra paths to search for icons
This commit is contained in:
parent
113e0ae1f9
commit
8fa6a01d04
1 changed files with 15 additions and 0 deletions
|
|
@ -39,6 +39,10 @@ pub struct Named {
|
|||
|
||||
/// Prioritizes SVG over PNG
|
||||
pub prefer_svg: bool,
|
||||
|
||||
/// Extra directories to search as flat paths before the icon theme chain.
|
||||
#[setters(skip)]
|
||||
pub extra_paths: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
impl Named {
|
||||
|
|
@ -52,19 +56,30 @@ impl Named {
|
|||
size: None,
|
||||
scale: None,
|
||||
prefer_svg: symbolic,
|
||||
extra_paths: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_extra_paths(mut self, paths: Vec<PathBuf>) -> Self {
|
||||
self.extra_paths = paths;
|
||||
self
|
||||
}
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
#[must_use]
|
||||
pub fn path(self) -> Option<PathBuf> {
|
||||
let name = &*self.name;
|
||||
let fallback = &self.fallback;
|
||||
let extra_paths = &self.extra_paths;
|
||||
let locate = |theme: &str, name| {
|
||||
let mut lookup = freedesktop_icons::lookup(name)
|
||||
.with_theme(theme.as_ref())
|
||||
.with_cache();
|
||||
|
||||
if !extra_paths.is_empty() {
|
||||
lookup = lookup.with_extra_paths(extra_paths);
|
||||
}
|
||||
|
||||
if let Some(scale) = self.scale {
|
||||
lookup = lookup.with_scale(scale);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue