57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package aluminum
|
|
|
|
import "fmt"
|
|
import "io/fs"
|
|
import "image"
|
|
import _ "image/png"
|
|
import "git.tebibyte.media/tomo/tomo"
|
|
import "git.tebibyte.media/tomo/tomo/data"
|
|
import "git.tebibyte.media/tomo/tomo/theme"
|
|
import "git.tebibyte.media/tomo/tomo/canvas"
|
|
|
|
type iconSet struct {
|
|
fs fs.FS
|
|
icons map[theme.IconSize] map[string] canvas.Texture
|
|
}
|
|
|
|
func (this *iconSet) get (size theme.IconSize, name string) canvas.Texture {
|
|
texture := this.icons[size][name]
|
|
if texture != nil {
|
|
return texture
|
|
} else {
|
|
texture = nil
|
|
defer func () { this.icons[size][name] = texture } ()
|
|
|
|
file, err := this.fs.Open(fmt.Sprint(size, "/", name, ".png"))
|
|
if err != nil { return texture }
|
|
defer file.Close()
|
|
image, _, err := image.Decode(file)
|
|
if err != nil { return texture }
|
|
|
|
texture = tomo.NewTexture(image)
|
|
return texture
|
|
}
|
|
}
|
|
|
|
func (this *iconSet) Icon (id theme.Icon, size theme.IconSize) canvas.Texture {
|
|
return this.get(size, fmt.Sprint("actions/", id))
|
|
}
|
|
|
|
func (this *iconSet) MimeIcon (mime data.Mime, size theme.IconSize) canvas.Texture {
|
|
texture := this.get(size, fmt.Sprint("mime/", mime))
|
|
if texture != nil {
|
|
return texture
|
|
} else {
|
|
return this.get(size, fmt.Sprint("mime-generic/", mime.Type))
|
|
}
|
|
}
|
|
|
|
func (this *iconSet) ApplicationIcon (id theme.ApplicationIcon, size theme.IconSize) canvas.Texture {
|
|
texture := this.get(size, fmt.Sprint("app/", id.Name))
|
|
if texture != nil {
|
|
return texture
|
|
} else {
|
|
return this.get(size, fmt.Sprint("app-generic/", id.Role))
|
|
}
|
|
}
|