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::theme::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([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 color(self, rgb: [u8; 3]) -> Self
pub fn color(self, rgb: [u8; 3]) -> Self
Set the foreground color for GTK symbolic icon colorization.
Sourcepub fn color_opt(self, rgb: Option<[u8; 3]>) -> Self
pub fn color_opt(self, rgb: Option<[u8; 3]>) -> Self
Set the foreground color if Some, leave default if None.
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.