iconTheme

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package iconTheme implements icon-theme-spec version 0.13.

Index

Constants

View Source
const (
	// ErrThemeNotFound indicates that a theme could not be found.
	ErrThemeNotFound = iconThemeError("theme not found")
	// ErrGroupMissing indicates that a required group was not found in an
	// index.theme file.
	ErrGroupMissing = iconThemeError("group missing")
	// ErrIconThemeGroupMissing indicates that the [Icon Theme] group was
	// not found while parsing an index.theme file.
	ErrIconThemeGroupMissing = iconThemeError("icon theme group missing")
	// ErrDirectoryGroupMissing indicates that a directory group was not
	// found while parsing an index.Theme file.
	ErrDirectoryGroupMissing = iconThemeError("directory group missing")
	// ErrEntryMissing indicates that a required entry was not found in an
	// index.theme file.
	ErrEntryMissing = iconThemeError("entry missing")
	// ErrBadIconSizeType indicates that an invalid value for an icon size
	// type was given.
	ErrBadIconSizeType = iconThemeError("bad icon size type")
	// ErrCircularDependency indicates that an icon theme depends on one of
	// its dependents.
	ErrCircularDependency = iconThemeError("circular dependency")
	// ErrIconNotFound indicates that an icon could not be found.
	ErrIconNotFound = iconThemeError("icon not found")
)

Variables

This section is empty.

Functions

func ThemeDirs

func ThemeDirs() ([]string, error)

ThemeDirs returns the set of directories in which themes should be looked for in order of preference.

It will return $HOME/.icons (for backwards compatibility), in $XDG_DATA_DIRS/icons and in /usr/share/pixmaps. Applications may further add their own icon directories to this list.

Types

type Directory

type Directory struct {
	Name      string
	Paths     []string
	Size      int
	Scale     int
	Context   string
	Type      IconSizeType
	MaxSize   int
	MinSize   int
	Threshold int
}

Directory represents a directory of an icon theme which directly contains icons.

func (Directory) Fits

func (directory Directory) Fits(size, scale int) bool

Fits returns whether icons in the directory fit the given size and scale.

func (Directory) SizeDistance

func (directory Directory) SizeDistance(size, scale int) int

SizeDistance returns how close the size of this directory's icons is to the given size. A smaller number is closer.

type Icon

type Icon struct {
	Path                  string
	FileType              IconFileType
	DisplayName           keyValue.Entry
	EmbeddedTextRectangle image.Rectangle
	AttachPoints          []image.Point
}

Icon represents an icon, and its associated data (if applicable).

type IconFileType

type IconFileType uint

IconFileType specifies the file type of an icon.

const (
	PNG IconFileType = iota
	SVG
	XPM
)

func (IconFileType) Extend

func (ty IconFileType) Extend(name string) string

Extend applies the file extension to a file name.

func (IconFileType) String

func (ty IconFileType) String() string

String returns a string representation of the file type.

type IconSizeType

type IconSizeType int

IconSizeType specifies how an icon can be scaled. Fixed icons cannot be scaled, scalable icons can be scaled to any size within a min and max range, and threshold icons can be scaled to any size within a certain distance of their normal size.

const (
	IconSizeTypeFixed IconSizeType = iota
	IconSizeTypeScalable
	IconSizeTypeThreshold
)

func IconSizeTypeFromString

func IconSizeTypeFromString(value string) (IconSizeType, error)

IconSizeTypeFromString converts a astring into an IconSizeType, returning an error if it could not be converted.

func (IconSizeType) String

func (ty IconSizeType) String() string

String returns a string representation of the type.

type Theme

type Theme struct {
	Name              keyValue.Entry
	Comment           keyValue.Entry
	Inherits          []Theme
	Directories       []Directory
	ScaledDirectories []Directory
	Hidden            bool
	Example           string
}

Theme represents an icon theme.

func FindTheme

func FindTheme(name string, path ...string) (Theme, error)

FindTheme returns the theme of the given name located within the given search paths. If no search path is provided, the result of ThemeDirs is used. This function will also recursively find and read inherited themes. If an inherited theme is malformed and cannot be read, hicolor will be used instead. The directory structure and inheritence tree of a theme are only determined when this function is run, if a theme has been changed and needs to be reloaded this function should be called again.

func FindThemeWarn

func FindThemeWarn(name string, path ...string) (Theme, error)

FindThemeWarn is like FindTheme, but emits warnings using the log package if it encounters a recoverable error (such as failing to parse/find an inherited theme).

func (Theme) FindIcon

func (theme Theme) FindIcon(name string, size, scale int, supported ...IconFileType) (Icon, error)

FindIcon finds the best icon of the given name for the given size and scale. If a list of supported filetypes is not given, { PNG, SVG, XPM } is used instead.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL