icon/registry.go
Functions
func DefaultMultiColorRegistry
func DefaultMultiColorRegistry() *MultiColorRegistry {
return defaultMultiColorRegistry
}
func DefaultRegistry
DefaultRegistry returns the global icon registry.
The default registry is pre-populated with all built-in icons. Additional
icons can be registered at any time using [Registry.Register].
func DefaultRegistry() *Registry {
return defaultRegistry
}
func Get
Get returns the icon with the given name and true if found, or a zero
IconData and false otherwise.
func (r *Registry) Get(name string) (IconData, bool) {
r.mu.RLock()
defer r.mu.RUnlock()
ic, ok := r.icons[name]
return ic, ok
}
func Get
Get returns the multi-color icon with the given name and true if found,
or a zero MultiColorIcon and false otherwise.
func (r *MultiColorRegistry) Get(name string) (MultiColorIcon, bool) {
r.mu.RLock()
defer r.mu.RUnlock()
ic, ok := r.icons[name]
return ic, ok
}
func Len
Len returns the number of icons in the registry.
func (r *Registry) Len() int {
r.mu.RLock()
defer r.mu.RUnlock()
return len(r.icons)
}
func Len
Len returns the number of multi-color icons in the registry.
func (r *MultiColorRegistry) Len() int {
r.mu.RLock()
defer r.mu.RUnlock()
return len(r.icons)
}
func Names
Names returns all registered icon names in no particular order.
func (r *Registry) Names() []string {
r.mu.RLock()
defer r.mu.RUnlock()
names := make([]string, 0, len(r.icons))
for name := range r.icons {
names = append(names, name)
}
return names
}
func Names
Names returns all registered multi-color icon names in no particular order.
func (r *MultiColorRegistry) Names() []string {
r.mu.RLock()
defer r.mu.RUnlock()
names := make([]string, 0, len(r.icons))
for name := range r.icons {
names = append(names, name)
}
return names
}
func NewMultiColorRegistry
NewMultiColorRegistry creates an empty multi-color icon registry.
func NewMultiColorRegistry() *MultiColorRegistry {
return &MultiColorRegistry{
icons: make(map[string]MultiColorIcon),
}
}
func NewRegistry
NewRegistry creates an empty icon registry.
func NewRegistry() *Registry {
return &Registry{
icons: make(map[string]IconData),
}
}
func Register
Register adds an icon to the registry, keyed by its Name field.
If an icon with the same name already exists, it is replaced.
func (r *Registry) Register(icon IconData) {
r.mu.Lock()
defer r.mu.Unlock()
r.icons[icon.Name] = icon
}
func Register
Register adds a multi-color icon to the registry, keyed by its Name field.
If an icon with the same name already exists, it is replaced.
func (r *MultiColorRegistry) Register(icon MultiColorIcon) {
r.mu.Lock()
defer r.mu.Unlock()
r.icons[icon.Name] = icon
}
Structs
type Registry struct
Registry is a thread-safe named icon registry.
Use [DefaultRegistry] to access the global registry, which is pre-populated
with all built-in icons. Create a custom registry with [NewRegistry] for
isolated icon sets.
type Registry struct {
mu sync.RWMutex
icons map[string]IconData
}
type MultiColorRegistry struct
MultiColorRegistry is a thread-safe named registry for multi-color icons.
Use [DefaultMultiColorRegistry] to access the global registry, which is
pre-populated with all built-in multi-color icons. Create a custom
registry with [NewMultiColorRegistry] for isolated icon sets.
type MultiColorRegistry struct {
mu sync.RWMutex
icons map[string]MultiColorIcon
}
DefaultMultiColorRegistry returns the global multi-color icon registry.
The default registry is pre-populated with all built-in multi-color icons
(file type icons and VCS icons). Additional icons can be registered at
any time using [MultiColorRegistry.Register].