Icons and styles use xyz.holanet.Nasin config
This commit is contained in:
@@ -6,9 +6,10 @@ import _ "embed"
|
||||
import _ "image/png"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "git.tebibyte.media/tomo/tomo/data"
|
||||
import "git.tebibyte.media/tomo/nasin/internal/util"
|
||||
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"
|
||||
|
||||
//go:embed assets/icons-small.png
|
||||
var atlasSmallBytes []byte
|
||||
@@ -35,7 +36,7 @@ const (
|
||||
iconXOfficeSpreadsheet = tomo.Icon("x-office-spreadsheet")
|
||||
)
|
||||
|
||||
func generateSource (data []byte, width int) map[tomo.Icon] canvas.Texture {
|
||||
func generateSource (data []byte, width int) (canvas.TextureCloser, map[tomo.Icon] canvas.Texture) {
|
||||
atlasImage, _, err := image.Decode(bytes.NewReader(data))
|
||||
if err != nil { panic(err) }
|
||||
atlasTexture := tomo.NewTexture(atlasImage)
|
||||
@@ -448,23 +449,26 @@ func generateSource (data []byte, width int) map[tomo.Icon] canvas.Texture {
|
||||
col(tomo.IconWeatherSnow)
|
||||
col(tomo.IconWeatherStorm)
|
||||
|
||||
return source
|
||||
return atlasTexture, source
|
||||
}
|
||||
|
||||
type iconSet struct {
|
||||
atlasSmall canvas.TextureCloser
|
||||
atlasLarge canvas.TextureCloser
|
||||
texturesSmall map[tomo.Icon] canvas.Texture
|
||||
texturesLarge map[tomo.Icon] canvas.Texture
|
||||
}
|
||||
|
||||
// New creates a new fallback icon set.
|
||||
func New () style.IconSet {
|
||||
return new(iconSet)
|
||||
func New () (style.IconSet, event.Cookie) {
|
||||
iconSet := new(iconSet)
|
||||
return iconSet, iconSet
|
||||
}
|
||||
|
||||
func (this *iconSet) ensure () {
|
||||
if this.texturesSmall != nil { return }
|
||||
this.texturesSmall = generateSource(atlasSmallBytes, 16)
|
||||
this.texturesLarge = generateSource(atlasLargeBytes, 32)
|
||||
this.atlasSmall, this.texturesSmall = generateSource(atlasSmallBytes, 16)
|
||||
this.atlasLarge, this.texturesLarge = generateSource(atlasLargeBytes, 32)
|
||||
}
|
||||
|
||||
func (this *iconSet) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.Texture {
|
||||
@@ -500,3 +504,12 @@ func (this *iconSet) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Textur
|
||||
return source[tomo.Icon(iconApplicationXGeneric)]
|
||||
}
|
||||
}
|
||||
|
||||
func (this *iconSet) Close () {
|
||||
if this.atlasSmall != nil {
|
||||
this.atlasSmall.Close()
|
||||
}
|
||||
if this.atlasLarge != nil {
|
||||
this.atlasLarge.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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