Icons and styles use xyz.holanet.Nasin config
This commit is contained in:
@@ -9,6 +9,7 @@ import "strings"
|
||||
import _ "image/png"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/tomo/event"
|
||||
import "git.tebibyte.media/tomo/tomo/canvas"
|
||||
import "git.tebibyte.media/tomo/backend/style"
|
||||
import "git.tebibyte.media/tomo/nasin/internal/util"
|
||||
@@ -17,27 +18,27 @@ import xdgIconTheme "git.tebibyte.media/tomo/xdg/icon-theme"
|
||||
type iconTheme struct {
|
||||
xdg xdgIconTheme.Theme
|
||||
fallback style.IconSet
|
||||
texturesSmall map[tomo.Icon] canvas.Texture
|
||||
texturesMedium map[tomo.Icon] canvas.Texture
|
||||
texturesLarge map[tomo.Icon] canvas.Texture
|
||||
texturesSmall map[tomo.Icon] canvas.TextureCloser
|
||||
texturesMedium map[tomo.Icon] canvas.TextureCloser
|
||||
texturesLarge map[tomo.Icon] canvas.TextureCloser
|
||||
}
|
||||
|
||||
func FindThemeWarn (name string, fallback style.IconSet, path ...string) (style.IconSet, error) {
|
||||
func FindThemeWarn (name string, fallback style.IconSet, path ...string) (style.IconSet, event.Cookie, error) {
|
||||
this := &iconTheme {
|
||||
fallback: fallback,
|
||||
texturesLarge: make(map[tomo.Icon] canvas.Texture),
|
||||
texturesMedium: make(map[tomo.Icon] canvas.Texture),
|
||||
texturesSmall: make(map[tomo.Icon] canvas.Texture),
|
||||
texturesLarge: make(map[tomo.Icon] canvas.TextureCloser),
|
||||
texturesMedium: make(map[tomo.Icon] canvas.TextureCloser),
|
||||
texturesSmall: make(map[tomo.Icon] canvas.TextureCloser),
|
||||
}
|
||||
|
||||
xdg, err := xdgIconTheme.FindThemeWarn(name, path...)
|
||||
if err != nil { return nil, err }
|
||||
if err != nil { return nil, nil, err }
|
||||
this.xdg = xdg
|
||||
|
||||
return this, nil
|
||||
return this, this, nil
|
||||
}
|
||||
|
||||
func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.Texture {
|
||||
func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.TextureCloser {
|
||||
switch size {
|
||||
case tomo.IconSizeMedium: return this.texturesMedium
|
||||
case tomo.IconSizeLarge: return this.texturesLarge
|
||||
@@ -45,7 +46,7 @@ func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.T
|
||||
}
|
||||
}
|
||||
|
||||
func (this *iconTheme) xdgIcon (name string, size tomo.IconSize) (canvas.Texture, bool) {
|
||||
func (this *iconTheme) xdgIcon (name string, size tomo.IconSize) (canvas.TextureCloser, bool) {
|
||||
// TODO use scaling factor instead of 1
|
||||
// find icon file
|
||||
icon, err := this.xdg.FindIcon(name, iconSizePixels(size), 1, xdgIconTheme.PNG)
|
||||
@@ -100,7 +101,20 @@ func (this *iconTheme) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Text
|
||||
}
|
||||
}
|
||||
|
||||
func (this *iconTheme) icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
|
||||
func (this *iconTheme) Close () {
|
||||
closeAllIn := func (mp map[tomo.Icon] canvas.TextureCloser) {
|
||||
for _, texture := range mp {
|
||||
if texture != nil {
|
||||
texture.Close()
|
||||
}
|
||||
}
|
||||
}
|
||||
closeAllIn(this.texturesSmall)
|
||||
closeAllIn(this.texturesMedium)
|
||||
closeAllIn(this.texturesLarge)
|
||||
}
|
||||
|
||||
func (this *iconTheme) icon (icon tomo.Icon, size tomo.IconSize) canvas.TextureCloser {
|
||||
if texture, ok := this.xdgIcon(XdgIconName(icon), size); ok {
|
||||
return texture
|
||||
}
|
||||
@@ -110,7 +124,7 @@ func (this *iconTheme) icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *iconTheme) mimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
|
||||
func (this *iconTheme) mimeIcon (mime data.Mime, size tomo.IconSize) canvas.TextureCloser {
|
||||
if texture, ok := this.xdgIcon(xdgFormatMime(mime), size); ok {
|
||||
return texture
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user