WIP icon loading
This commit is contained in:
55
icons.go
Normal file
55
icons.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package aluminum
|
||||
|
||||
import "os"
|
||||
import "fs"
|
||||
import "fmt"
|
||||
import "image"
|
||||
import "image/png"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/theme"
|
||||
import "git.tebibyte.media/tomo/tomo/input"
|
||||
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 nil }
|
||||
defer file.Close()
|
||||
image, _, err := image.Decode(file)
|
||||
if err != nil { return nil }
|
||||
texture = tomo.NewTexture(image)
|
||||
}
|
||||
}
|
||||
|
||||
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/", app.Role))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user