WIP icon loading

This commit is contained in:
Sasha Koshka 2023-08-29 21:28:39 -04:00
parent 07f41dc39d
commit e7c5b2d5b9
2 changed files with 56 additions and 25 deletions

55
icons.go Normal file
View 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))
}
}

View File

@ -47,7 +47,7 @@ var gutterColor = hex(0xbfc6d1FF)
var gutterColorHovered = hex(0xc5cbd6FF)
type Theme struct {
initialized bool
iconSet
}
func (this *Theme) RGBA (id theme.Color) (r, g, b, a uint32) {
@ -221,27 +221,3 @@ func (this *Theme) Apply (object tomo.Object, role theme.Role) event.Cookie {
return event.MultiCookie()
}
func (this *Theme) Icon (theme.Icon, theme.IconSize) canvas.Texture {
this.ensure()
// TODO
return nil
}
func (this *Theme) MimeIcon (data.Mime, theme.IconSize) canvas.Texture {
this.ensure()
// TODO
return nil
}
func (this *Theme) ApplicationIcon (theme.ApplicationIcon, theme.IconSize) canvas.Texture {
this.ensure()
// TODO
return nil
}
func (this *Theme) ensure () {
if this.initialized { return }
this.initialized = true
// TODO
}