WIP icon loading
This commit is contained in:
parent
07f41dc39d
commit
e7c5b2d5b9
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))
|
||||
}
|
||||
}
|
26
theme.go
26
theme.go
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user