Skip to main content

Icons

Struct Icons 

Source
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

Source

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.

Source

pub fn theme(&self, theme_name: &str) -> Option<Arc<Theme>>

Access a known icon theme by name

Source

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.

Source

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.

Source

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.

Source

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.

Source

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();

Trait Implementations§

Source§

impl Default for Icons

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<Icons> for IconsCache

Available on crate feature cache only.
Source§

fn from(icons: Icons) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl Freeze for Icons

§

impl RefUnwindSafe for Icons

§

impl Send for Icons

§

impl Sync for Icons

§

impl Unpin for Icons

§

impl UnsafeUnpin for Icons

§

impl UnwindSafe for Icons

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.