lookupIcon

Lookup icon alternatives in icon themes. It uses icon theme cache wherever it's loaded. If searched icon is found in some icon theme all subsequent themes are ignored.

This function may require many stat calls, so beware. Use subdirFilter to filter icons by icontheme.file.IconSubDir properties (e.g. by size or context) to decrease the number of searchable items and allocations. Loading icontheme.cache.IconThemeCache may also descrease the number of stats.

void
lookupIcon
(
alias subdirFilter = (a => true)
IconThemes
BaseDirs
Exts
OutputRange
)
(
string iconName
,
IconThemes iconThemes
,,,
OutputRange sink
,
Flag!"reverse" reverse = No.reverse
)
if (
isInputRange!(IconThemes) &&
isForwardRange!(BaseDirs)
&&
isForwardRange!(Exts)
&&
is(ElementType!IconThemes : const(IconThemeFile))
&&
is(ElementType!BaseDirs : string)
&&
is(ElementType!Exts : string)
&&
isOutputRange!(OutputRange, IconSearchResult!(ElementType!IconThemes))
)

Parameters

iconName string

Icon name.

iconThemes IconThemes

Icon themes to search icon in.

searchIconDirs BaseDirs

Case icon directories.

extensions Exts

Possible file extensions of needed icon file, in order of preference.

sink OutputRange

Output range accepting IconSearchResults.

reverse Flag!"reverse"

Iterate over icon theme sub-directories in reverse way. Usually directories with larger icon size are listed the last, so this parameter may speed up the search when looking for the largest icon. Note: Specification says that extension must be ".png", ".xpm" or ".svg", though SVG is not required to be supported. Some icon themes also contain .svgz images.

Examples

lookupIcon!(subdir => subdir.context == "Places" && subdir.size >= 32)(
    "folder", iconThemes, baseIconDirs(), [".png", ".xpm"],
    delegate void (IconSearchResult!IconThemeFile item) {
        writefln("Icon file: %s. Context: %s. Size: %s. Theme: %s", item.filePath, item.subdir.context, item.subdir.size, item.iconTheme.displayName);
    });

See Also

icontheme.paths.baseIconDirs, lookupFallbackIcon

Meta