Documentation
¶
Overview ¶
Package sfsymbols draws Apple's SF Symbols, as the running macOS has them, for native UI.
sfsymbols.Symbol(c, "gearshape") sfsymbols.Symbol(c, "trash").Size(20).Color(t.Accent).Weight(sfsymbols.Semibold).Fill()
Symbol shows one as SwiftUI's Image(systemName:) does; Image gives the bitmap, for drawing with a ui.Painter.
The symbols are read from the system: AppKit draws each with its own design and weight, and the plugin copies the pixels. Nothing of Apple's artwork is in the app or its build. Where the system has no symbol of a name, and on every other OS, Image says so and Symbol draws its Fallback instead.
Index ¶
- func Available() bool
- func Image(name string, px int, col ui.Color, o Options) (ui.ImageSource, bool)
- func Names() []string
- type Options
- type SymbolElement
- func (e SymbolElement) Color(col ui.Color) SymbolElement
- func (e SymbolElement) Fallback(svg *ui.SVG) SymbolElement
- func (e SymbolElement) Fill() SymbolElement
- func (e SymbolElement) Natural() SymbolElement
- func (e SymbolElement) Size(size float32) SymbolElement
- func (e SymbolElement) Weight(w Weight) SymbolElement
- type Weight
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Available ¶
func Available() bool
Available reports whether this system draws SF Symbols at all. It does not.
Types ¶
type Options ¶
type Options struct {
// Natural draws the symbol at the size it has beside others of the
// same point size, rather than filling its box: a cross stays smaller
// than a wide rectangle, as SF Symbols balance them.
Natural bool
// Weight is the weight of the symbol's strokes, Regular by default.
Weight Weight
}
Options of a symbol's drawing.
type SymbolElement ¶
SymbolElement is the element Symbol makes: a ui.Element, with the symbol's own modifiers. Each returns the element, so they chain as SwiftUI's do, and the ui.Element's own methods (Margin, Tooltip, ...) are there too.
func Symbol ¶
func Symbol(c *ui.Context, name string) SymbolElement
Symbol shows the SF Symbol named name, as SwiftUI's Image(systemName:): at the theme's font size and in its text color, drawn sharp at the display's scale, and named for assistive technology.
sfsymbols.Symbol(c, "gearshape") sfsymbols.Symbol(c, "trash").Size(20).Color(t.Accent).Weight(sfsymbols.Semibold).Fill() sfsymbols.Symbol(c, "sparkles").Fallback(sparkles) // an SVG where the system has none
Where the system has no symbol of that name, on another OS or a macOS without it, it draws its Fallback, or nothing, at the same size.
func (SymbolElement) Color ¶
func (e SymbolElement) Color(col ui.Color) SymbolElement
Color draws the symbol in col rather than the theme's text color, as SwiftUI's foregroundStyle.
func (SymbolElement) Fallback ¶
func (e SymbolElement) Fallback(svg *ui.SVG) SymbolElement
Fallback draws svg, in the symbol's color, where the system has no such symbol.
func (SymbolElement) Fill ¶
func (e SymbolElement) Fill() SymbolElement
Fill draws the symbol's filled variant where it has one ("trash.fill" for "trash"), and the symbol itself where it has none, as SwiftUI's symbolVariant(.fill).
func (SymbolElement) Natural ¶
func (e SymbolElement) Natural() SymbolElement
Natural draws the symbol at the size it has beside others of the same point size, rather than filling its box: see Options.Natural.
func (SymbolElement) Size ¶
func (e SymbolElement) Size(size float32) SymbolElement
Size sets the symbol's box, size DIPs square.
func (SymbolElement) Weight ¶
func (e SymbolElement) Weight(w Weight) SymbolElement
Weight draws the symbol's strokes at w, as SwiftUI's fontWeight.