Skip to main content

FreedesktopLoader

Struct FreedesktopLoader 

Source
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>

Source

pub fn new(id: impl Into<IconId<'a>>) -> Self

Create a freedesktop loader. Defaults: size 24, no fg_color, system theme.

Source

pub fn size(self, size: u16) -> Self

Set the requested icon size in pixels (default 24).

Source

pub fn color(self, rgb: [u8; 3]) -> Self

Set the foreground color for GTK symbolic icon colorization.

Source

pub fn color_opt(self, rgb: Option<[u8; 3]>) -> Self

Set the foreground color if Some, leave default if None.

Source

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).

Source

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.

Source

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.

Trait Implementations§

Source§

impl<'a> Debug for FreedesktopLoader<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for FreedesktopLoader<'a>

§

impl<'a> !Send for FreedesktopLoader<'a>

§

impl<'a> !Sync for FreedesktopLoader<'a>

§

impl<'a> !UnwindSafe for FreedesktopLoader<'a>

§

impl<'a> Freeze for FreedesktopLoader<'a>

§

impl<'a> Unpin for FreedesktopLoader<'a>

§

impl<'a> UnsafeUnpin for FreedesktopLoader<'a>

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more