pub struct Icons {
pub standalone_icons: HashMap<String, IconFile>,
pub themes: HashMap<OsString, Arc<Theme>>,
}Expand description
Main struct to locate icon files.
Create this using Icons::new for the standard configuration, or use IconSearch if you
wish to tune where icons can be found.
§Example
use icon::Icons;
Icons::new().find_icon("firefox", 32, 1, "hicolor");Fields§
§standalone_icons: HashMap<String, IconFile>Map of “standalone” icons (icons not belonging to any icon theme) to their path.
themes: HashMap<OsString, Arc<Theme>>Map of internal theme names to their corresponding Theme
Implementations§
Source§impl Icons
impl Icons
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new Icons, performing a search in the standard directories.
This function collects all standalone icons and icon themes on the system.
To configure what directories are searched, use IconSearch instead.
Sourcepub fn find_default_icon(
&self,
icon_name: &str,
size: u32,
scale: u32,
) -> Option<IconFile>
pub fn find_default_icon( &self, icon_name: &str, size: u32, scale: u32, ) -> Option<IconFile>
Like find_icon, with theme being "hicolor", which is the default icon theme.
Sourcepub fn find_icon(
&self,
icon_name: &str,
size: u32,
scale: u32,
theme: &str,
) -> Option<IconFile>
pub fn find_icon( &self, icon_name: &str, size: u32, scale: u32, theme: &str, ) -> Option<IconFile>
Look up an icon by name, size, scale and theme.
- If no theme by the given name exists, the
"hicolor"theme (default theme) is used instead. - If the icon is not found in the provided theme, its parents are checked.
- 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.
Sourcepub fn find_standalone_icon(&self, icon_name: &str) -> Option<IconFile>
pub fn find_standalone_icon(&self, icon_name: &str) -> Option<IconFile>
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.
Sourcepub fn find_all_icons(
&self,
) -> impl Iterator<Item = (Arc<Theme>, &DirectoryIndex, IconFile)>
pub fn find_all_icons( &self, ) -> impl Iterator<Item = (Arc<Theme>, &DirectoryIndex, IconFile)>
Find all icons in all themes, in all of their directories.
Also see find_all_icons_filtered.
Sourcepub fn find_all_icons_filtered<'a>(
&'a self,
filter_theme: impl Fn(&Theme) -> bool + 'a,
filter_directory: impl Fn(&DirectoryIndex) -> bool + 'a,
filter_icon: impl Fn(&IconFile) -> bool + Clone + 'a,
) -> impl Iterator<Item = (Arc<Theme>, &'a DirectoryIndex, IconFile)>
pub fn find_all_icons_filtered<'a>( &'a self, filter_theme: impl Fn(&Theme) -> bool + 'a, filter_directory: impl Fn(&DirectoryIndex) -> bool + 'a, filter_icon: impl Fn(&IconFile) -> bool + Clone + 'a, ) -> impl Iterator<Item = (Arc<Theme>, &'a DirectoryIndex, IconFile)>
Find all icons in all themes, in all of their directories, filtered at each stage by a predicate.
This happens lazily: the function returns an iterator that only does the required work when you advance it.
The output of this function does not include standalone icons.
If you need a full list of icons, use this method and chain it together with the content of
standalone_icons
This method is not meant for finding icons by name / size; use find_icon for that.
§Example
Find all icons belonging to a theme called “Adwaita”, in a directory for icons size ≤ 128px:
use icon::{Icons, IconFile};
let icons = Icons::new();
let adwaita: Vec<IconFile> = icons
.find_all_icons_filtered(
|theme| theme.info.internal_name == "Adwaita",
|dir| dir.size <= 128,
|_| true,
)
.map(|(_, _, icon)| icon)
.collect();