Struct icon_loader::IconLoader

source ·
pub struct IconLoader { /* private fields */ }
Expand description

The central icon loader struct.

It lets you load and cache named theme icons from system themes as well as custom themes.

Implementations§

source§

impl IconLoader

source

pub fn new() -> Self

Creates a new IconLoader with default settings.

source

pub fn new_kde() -> Result<Self>

Creates a new KDE IconLoader. This is a convenience function.

source

pub fn new_gtk() -> Result<Self>

Creates a new GTK IconLoader. This is a convenience function.

source

pub fn load_icon(&self, icon_name: impl AsRef<str>) -> Option<Arc<Icon>>

Loads the icon with the name icon_name from the current icon theme. If the icon cannot be found, it will be looked for in the fallback icon theme. If it cannot be found in the fallback theme, None is returned.

source

pub fn theme_name(&self) -> &str

Returns the currently used theme name.

See also IconLoader::update_theme_name().

source

pub fn fallback_theme_name(&self) -> &str

Returns the currently used fallback theme name.

See also IconLoader::set_fallback_theme_name().

source

pub fn search_paths(&self) -> Cow<'_, [PathBuf]>

Returns the paths that are searched for icon themes.

source

pub fn set_search_paths(&mut self, search_paths: impl Into<SearchPaths>)

Sets the paths where to search for icon themes.

Arguments
  • search_paths - The paths where to look for icon themes. Anything that implements IntoIterator<Item = Into<PathBuf>> can be used.
Examples

Custom search paths:

use icon_loader::IconLoader;

let mut loader = IconLoader::new();
loader.set_search_paths(&["/path/to/icon/themes", "/other/path/to/icon/themes"]);

System search paths:

use icon_loader::{IconLoader, SearchPaths};

let mut loader = IconLoader::new();
loader.set_search_paths(SearchPaths::System);

By default these are the system icon paths.

source

pub fn set_theme_name_provider( &mut self, theme_name_provider: impl Into<ThemeNameProvider> )

Sets the way in which the used theme name is determined.

Arguments
  • theme_name_provider - The provider of the default icon theme name. Anything that implements Into<ThemeNameProvider> can be used.
Examples

User defined theme name:

use icon_loader::IconLoader;

let mut loader = IconLoader::new();
loader.set_theme_name_provider("theme_name");

KDE system theme:

use icon_loader::{IconLoader, ThemeNameProvider};

let mut loader = IconLoader::new();
loader.set_theme_name_provider(ThemeNameProvider::KDE);

IconLoader::update_theme_name() needs to be called after setting a new theme name provider.

source

pub fn update_theme_name(&mut self) -> Result<()>

Queries the set ThemeNameProvider for the theme name to be used. Returns an error, if the set ThemeNameProvider returns an error or the theme with the returned name cannot be found.

Set a theme name provider with IconLoader::set_theme_name_provider().

source

pub fn set_fallback_theme_name( &mut self, fallback_theme_name: impl Into<String> )

Sets a new fallback theme name. If an icon cannot be found in the set theme, it will be looked for in the fallback theme. The default fallback theme name is ‘hicolor’.

source

pub fn theme_exists(&self, theme_name: impl AsRef<str>) -> bool

Returns whether a theme with the name theme_name exists in the current search paths.

Trait Implementations§

source§

impl Debug for IconLoader

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for IconLoader

source§

fn default() -> Self

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.