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
impl IconLoader
sourcepub fn load_icon(&self, icon_name: impl AsRef<str>) -> Option<Arc<Icon>>
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.
sourcepub fn theme_name(&self) -> &str
pub fn theme_name(&self) -> &str
Returns the currently used theme name.
See also IconLoader::update_theme_name()
.
sourcepub fn fallback_theme_name(&self) -> &str
pub fn fallback_theme_name(&self) -> &str
Returns the currently used fallback theme name.
See also IconLoader::set_fallback_theme_name()
.
sourcepub fn search_paths(&self) -> Cow<'_, [PathBuf]>
pub fn search_paths(&self) -> Cow<'_, [PathBuf]>
Returns the paths that are searched for icon themes.
sourcepub fn set_search_paths(&mut self, search_paths: impl Into<SearchPaths>)
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 implementsIntoIterator<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.
sourcepub fn set_theme_name_provider(
&mut self,
theme_name_provider: impl Into<ThemeNameProvider>
)
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 implementsInto<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.
sourcepub fn update_theme_name(&mut self) -> Result<()>
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()
.
sourcepub fn set_fallback_theme_name(
&mut self,
fallback_theme_name: impl Into<String>
)
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’.
sourcepub fn theme_exists(&self, theme_name: impl AsRef<str>) -> bool
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.