pub struct FreedesktopLoader<'a> { /* private fields */ }Expand description
Loader for freedesktop.org icon themes (GTK / Linux).
Honors .theme() for BOTH role-based and name-based lookups — unlike
the previous single-struct design, no dispatch layer can silently
drop the theme override.
An icon comes only from the theme or from a theme in the Inherits=
chain its index.theme declares, searched depth-first in declared
order as the Icon Theme Specification’s lookup does, never from
hicolor unless hicolor is the theme asked for, nor from a loose
file in an icon directory or /usr/share/pixmaps. An icon the theme
and its parents lack is None, and so is every icon of a theme that
is not installed.
The installed themes are read once, at the process’s first freedesktop
lookup (freedesktop-icons caches them the same way), and a theme’s
Inherits= chain at its own first lookup, so a theme installed after
that is not searched, and a changed Inherits= is not seen, until the
process restarts.
use native_theme::icons::FreedesktopLoader;
use native_theme::icons::IconRole;
// By role, system theme:
let _icon = FreedesktopLoader::new(IconRole::ActionCopy).load();
// By name, explicit theme + size + symbolic fg color:
let _icon = FreedesktopLoader::new("edit-copy")
.theme("Adwaita")
.size(48)
.color(native_theme::Rgba::rgb(0, 0, 0))
.load();Implementations§
Source§impl<'a> FreedesktopLoader<'a>
impl<'a> FreedesktopLoader<'a>
Sourcepub fn new(id: impl Into<IconId<'a>>) -> Self
pub fn new(id: impl Into<IconId<'a>>) -> Self
Create a freedesktop loader. Defaults: size 24, no fg_color, system theme.
Sourcepub fn any(names: &'a [&'a str]) -> Self
pub fn any(names: &'a [&'a str]) -> Self
Create a loader for the first of names the theme has, for a
concept icon themes name differently (Breeze’s view-visible,
Adwaita’s view-reveal). Each theme of the chain (see
FreedesktopLoader) is searched for every name, in order, before
the theme it inherits from, so the theme’s own icon under a later
name wins over its parent’s under an earlier one: Adwaita’s
starred-symbolic over AdwaitaLegacy’s raster emblem-favorite,
which Self::new tried name by name would load. Within a theme a
name is tried as <name>-symbolic, then as itself. Every name is
looked up in the one theme and its chain, so no icon comes from
another set. Defaults as Self::new; no names load None.
With one name, any(&[name]) differs from new(name) in one case: a
theme that has the plain name while a theme it inherits from has
<name>-symbolic. any takes the theme’s own plain icon, as it
searches a theme before its parent; new searches the whole chain for
the symbolic form first and takes the parent’s.
use native_theme::icons::FreedesktopLoader;
let _eye = FreedesktopLoader::any(&["view-visible", "view-reveal"])
.theme("Adwaita")
.load();Sourcepub fn size(self, size: u32) -> Self
pub fn size(self, size: u32) -> Self
Set the requested icon size in pixels (default 24), clamped to
1..=MAX_ICON_SIZE: a larger size is looked up as 512, in the
theme’s directory nearest it.
Sourcepub fn color(self, color: Rgba) -> Self
pub fn color(self, color: Rgba) -> Self
Set the foreground color for GTK symbolic icon colorization; its alpha is ignored: the icon keeps its own coverage.
Sourcepub fn color_opt(self, color: Option<Rgba>) -> Self
pub fn color_opt(self, color: Option<Rgba>) -> Self
Set the foreground color if Some, leave default if None; its
alpha is ignored, as in Self::color.
Sourcepub fn theme(self, theme: &'a str) -> Self
pub fn theme(self, theme: &'a str) -> Self
Override the freedesktop icon theme (e.g. “Adwaita”, “breeze”).
When unset, uses the system-detected theme, and searches no theme
where detection fails (see Self::load).
Sourcepub fn load(self) -> Option<IconData>
pub fn load(self) -> Option<IconData>
Load the icon, returning its data.
None when neither the theme nor a theme it inherits from has the
icon (see FreedesktopLoader).
With no theme set, the icon comes from the system’s
icon theme, and where that cannot be detected no theme is searched,
as none stands in for the undetected one: a role or a name gives
None, and a custom IconProvider gives only its own freedesktop
SVG (IconProvider::icon_svg), which depends on no theme, where it
has one. system_icon_theme()
gives the reason.
Requires the system-icons feature, and Linux; None otherwise.
Sourcepub fn load_indicator(theme: Option<&str>) -> Option<AnimatedIcon>
pub fn load_indicator(theme: Option<&str>) -> Option<AnimatedIcon>
Load the theme’s animated process-working spinner.
theme of None uses the system-detected theme, and gives None
where detection fails — no theme stands in for the undetected one;
Some(t) overrides.
Associated function (no self) — the spinner is a property of the
theme, not of any particular icon id. Found only where
Self::load would find an icon: in the theme or a theme it
inherits from, never in hicolor unless that is the theme.
Requires the system-icons feature, and Linux; None otherwise.