Documentation
¶
Overview ¶
Package fyne_iconkit provides the shared runtime behind the fyne_* icon packages: loading SVG icons from an fs.FS, caching them as fyne.Resource, staining monochrome icons with an arbitrary color and rasterizing them to PNG.
Icon packages usually wrap a single package-level Set around an embedded directory and generate name constants with cmd/iconconst.
Index ¶
- func Outline(src []byte) (out []byte, err error)
- func Stain(src []byte, c color.Color) []byte
- type Set
- func (s *Set) Has(name string) bool
- func (s *Set) Icon(name string, stainColor ...color.Color) (fyne.Resource, error)
- func (s *Set) MustIcon(name string, stainColor ...color.Color) fyne.Resource
- func (s *Set) Names() []string
- func (s *Set) PNG(name string, size int, stainColor ...color.Color) ([]byte, error)
- func (s *Set) Source(name string) ([]byte, error)
- func (s *Set) StainedSource(name string, c color.Color) ([]byte, error)
- type StainableResource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Outline ¶ added in v0.3.0
Outline converts a monochrome SVG into one that only consists of filled <path> elements with fill="currentColor": strokes become filled outlines. Translucent parts get a fill-opacity.
Fyne recolors SVGs by replacing their fill colors. On the way it drops stroke colors, stroke attributes of the root element and elements like <line> or <polyline>, so stroked icons vanish or turn into blobs in theme.NewThemedResource, NewColoredResource, NewDisabledResource and in widgets that use them (disabled buttons and menu items, important buttons, selected tabs). Outlined icons are recolored correctly, like Fyne's own icons; only the opacity of translucent parts is lost.
Fyne also does not scale stroke widths with the rendered size; outlines scale like any other shape.
Curves are flattened to lines that deviate at most 1/100 of a view box unit from the exact shape.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a collection of SVG icons stored in a directory of an fs.FS. All methods are safe for concurrent use.
func NewSet ¶
NewSet returns a Set of multi-colored icons (e.g. flags). Icons are served as they are; stain colors passed to Icon are ignored.
func NewStainableSet ¶
NewStainableSet returns a Set of monochrome icons that use "currentColor". Icons are always stained before use; without an explicit color the theme's foreground color at the time of the call is used.
func (*Set) Icon ¶
Icon returns the named icon as a cached fyne.Resource.
For stainable sets the result is a StainableResource colored with the first stain color, or with the current theme foreground color if none is given. Its content is the Outline of the icon, so Fyne can recolor it (e.g. in disabled buttons or theme.NewThemedResource) and scales its strokes. For other sets stain colors are ignored.
func (*Set) MustIcon ¶
MustIcon is like Icon but logs the error via fyne.LogError and returns theme.ErrorIcon() if the icon cannot be loaded.
func (*Set) PNG ¶
PNG rasterizes the named icon to PNG. size is the length of the longer edge in pixels; the aspect ratio of the SVG view box is preserved.
Icons of stainable sets are stained with the first stain color, or black if none is given. For other sets stain colors are ignored.
type StainableResource ¶
type StainableResource interface {
fyne.Resource
// StainColor returns the color the resource is currently stained with.
StainColor() color.Color
// Stain returns the same icon stained with c.
Stain(c color.Color) (fyne.Resource, error)
// MustStain is like Stain but returns theme.ErrorIcon() on failure.
MustStain(c color.Color) fyne.Resource
}
StainableResource is a monochrome icon resource that can be re-colored.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
iconconst
command
Command iconconst generates one Go variable per *.svg icon in a directory.
|
Command iconconst generates one Go variable per *.svg icon in a directory. |
|
Package iconupdate imports releases of an icon set published on npm into an icon package built on fyne_iconkit, keeping renamed icons usable.
|
Package iconupdate imports releases of an icon set published on npm into an icon package built on fyne_iconkit, keeping renamed icons usable. |
|
internal
|
|
|
constgen
Package constgen generates Go variables for the icons in a directory.
|
Package constgen generates Go variables for the icons in a directory. |