62 lines
980 B
Go
62 lines
980 B
Go
package main
|
|
|
|
import (
|
|
"embed"
|
|
"strings"
|
|
)
|
|
|
|
// Embed the built-in icons into the binary.
|
|
//
|
|
//go:embed icons/*
|
|
var fs embed.FS
|
|
|
|
// Icon implements a fyne.Resource and provides built-in icon data.
|
|
type Icon struct {
|
|
name string
|
|
data []byte
|
|
}
|
|
|
|
func (i Icon) Empty() bool {
|
|
return len(i.data) == 0
|
|
}
|
|
|
|
func (i Icon) Name() string {
|
|
return i.name
|
|
}
|
|
|
|
func (i Icon) Content() []byte {
|
|
return i.data
|
|
}
|
|
|
|
// A map of all the built-in icons by name.
|
|
var (
|
|
icons = map[string]Icon{}
|
|
iconNames = []string{}
|
|
)
|
|
|
|
func LoadIcons() {
|
|
filenames, err := fs.ReadDir("icons")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
for _, icon := range filenames {
|
|
basename := strings.TrimSuffix(icon.Name(), ".png")
|
|
iconNames = append(iconNames, basename)
|
|
|
|
// Populate the icons map too.
|
|
if _, ok := icons[basename]; !ok {
|
|
bin, err := fs.ReadFile("icons/" + icon.Name())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
i := Icon{
|
|
name: basename,
|
|
data: bin,
|
|
}
|
|
icons[basename] = i
|
|
}
|
|
}
|
|
}
|