hnnggg icons
This commit is contained in:
		
							parent
							
								
									1b489485da
								
							
						
					
					
						commit
						d597f79a16
					
				
							
								
								
									
										
											BIN
										
									
								
								assets/mime-generic-medium.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/mime-generic-medium.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 912 B  | 
							
								
								
									
										
											BIN
										
									
								
								assets/mime-generic-medium.xcf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/mime-generic-medium.xcf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								assets/mime-medium.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								assets/mime-medium.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 17 KiB  | 
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							@ -3,6 +3,6 @@ module git.tebibyte.media/tomo/aluminum
 | 
			
		||||
go 1.20
 | 
			
		||||
 | 
			
		||||
require (
 | 
			
		||||
	git.tebibyte.media/tomo/tomo v0.26.1
 | 
			
		||||
	git.tebibyte.media/tomo/tomo v0.27.0
 | 
			
		||||
	golang.org/x/image v0.11.0
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								go.sum
									
									
									
									
									
								
							@ -1,5 +1,5 @@
 | 
			
		||||
git.tebibyte.media/tomo/tomo v0.26.1 h1:V5ciRuixMYb79aAawgquFEfJ1icyEmMKBKFPWwi94NE=
 | 
			
		||||
git.tebibyte.media/tomo/tomo v0.26.1/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
 | 
			
		||||
git.tebibyte.media/tomo/tomo v0.27.0 h1:gCwxQe0qm1hZLfHkMI3OccNMC/lB1cfs4BbaMz/bXug=
 | 
			
		||||
git.tebibyte.media/tomo/tomo v0.27.0/go.mod h1:C9EzepS9wjkTJjnZaPBh22YvVPyA4hbBAJVU20Rdmps=
 | 
			
		||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 | 
			
		||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										84
									
								
								icons.go
									
									
									
									
									
								
							
							
						
						
									
										84
									
								
								icons.go
									
									
									
									
									
								
							@ -1,56 +1,66 @@
 | 
			
		||||
package aluminum
 | 
			
		||||
 | 
			
		||||
import "fmt"
 | 
			
		||||
import "io/fs"
 | 
			
		||||
import "io"
 | 
			
		||||
import "image"
 | 
			
		||||
import _ "image/png"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo/data"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo/theme"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo/canvas"
 | 
			
		||||
 | 
			
		||||
type iconSet struct {
 | 
			
		||||
	fs fs.FS
 | 
			
		||||
	icons map[theme.IconSize] map[string] canvas.Texture
 | 
			
		||||
type iconIndex interface {
 | 
			
		||||
	~int | ~string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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 } ()
 | 
			
		||||
type iconEntry[T iconIndex] struct {
 | 
			
		||||
	position image.Point
 | 
			
		||||
	index T
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		file, err := this.fs.Open(fmt.Sprint(size, "/", name, ".png"))
 | 
			
		||||
		if err != nil { return texture }
 | 
			
		||||
		defer file.Close()
 | 
			
		||||
		image, _, err := image.Decode(file)
 | 
			
		||||
		if err != nil { return texture }
 | 
			
		||||
		
 | 
			
		||||
		texture = tomo.NewTexture(image)
 | 
			
		||||
		return texture
 | 
			
		||||
func i[T iconIndex] (x, y int, index T) iconEntry[T] {
 | 
			
		||||
	return iconEntry[T] {
 | 
			
		||||
		position: image.Pt(x, y),
 | 
			
		||||
		index:    index,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *iconSet) Icon (id theme.Icon, size theme.IconSize) canvas.Texture {
 | 
			
		||||
	return this.get(size, fmt.Sprint("actions/", id))
 | 
			
		||||
type iconSet[T iconIndex] struct {
 | 
			
		||||
	icons map[theme.IconSize] map[T] canvas.Texture
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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[T]) Get (index T,size theme.IconSize) canvas.Texture {
 | 
			
		||||
	return this.icons[size][index]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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/", id.Role))
 | 
			
		||||
func (this *iconSet[T]) Init (
 | 
			
		||||
	small, medium, large io.Reader,
 | 
			
		||||
	rows, columns        int,
 | 
			
		||||
	icons                ...iconEntry[T],
 | 
			
		||||
) {
 | 
			
		||||
	this.icons = make(map[theme.IconSize] map[T] canvas.Texture)
 | 
			
		||||
	this.initFor(theme.IconSizeSmall,  small,  rows, columns, icons...)
 | 
			
		||||
	this.initFor(theme.IconSizeMedium, medium, rows, columns, icons...)
 | 
			
		||||
	this.initFor(theme.IconSizeLarge,  large,  rows, columns, icons...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *iconSet[T]) initFor (
 | 
			
		||||
	size          theme.IconSize,
 | 
			
		||||
	file          io.Reader,
 | 
			
		||||
	rows, columns int,
 | 
			
		||||
	icons         ...iconEntry[T],
 | 
			
		||||
) {
 | 
			
		||||
	if file == nil { return }
 | 
			
		||||
	
 | 
			
		||||
	atlasImage, _, err := image.Decode(file)
 | 
			
		||||
	if err != nil { panic(err) }
 | 
			
		||||
	atlas := tomo.NewTexture(atlasImage)
 | 
			
		||||
	cellW := atlasImage.Bounds().Dx() / columns
 | 
			
		||||
	cellH := atlasImage.Bounds().Dy() / rows
 | 
			
		||||
	cellSize := image.Rect(0, 0, cellW, cellH)
 | 
			
		||||
 | 
			
		||||
	this.icons[size] = make(map[T] canvas.Texture)
 | 
			
		||||
	for _, icon := range icons {
 | 
			
		||||
		offset := image.Pt (
 | 
			
		||||
			icon.position.X * cellW,
 | 
			
		||||
			icon.position.Y * cellH)
 | 
			
		||||
		this.icons[size][icon.index] = atlas.Clip(cellSize.Add(offset))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										77
									
								
								theme.go
									
									
									
									
									
								
							
							
						
						
									
										77
									
								
								theme.go
									
									
									
									
									
								
							@ -1,12 +1,22 @@
 | 
			
		||||
package aluminum
 | 
			
		||||
 | 
			
		||||
import "bytes"
 | 
			
		||||
import "image"
 | 
			
		||||
import _ "embed"
 | 
			
		||||
import _ "image/png"
 | 
			
		||||
import "image/color"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo"
 | 
			
		||||
import "golang.org/x/image/font/basicfont"
 | 
			
		||||
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/event"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo/canvas"
 | 
			
		||||
 | 
			
		||||
//go:embed assets/mime-generic-medium.png
 | 
			
		||||
var genericMimeIconsMedium []byte
 | 
			
		||||
//go:embed assets/mime-medium.png
 | 
			
		||||
var mimeIconsMedium []byte
 | 
			
		||||
 | 
			
		||||
func hex (color uint32) (c color.RGBA) {
 | 
			
		||||
	c.A = uint8(color)
 | 
			
		||||
@ -45,7 +55,12 @@ var gutterColor        = hex(0xbfc6d1FF)
 | 
			
		||||
var gutterColorHovered = hex(0xc5cbd6FF)
 | 
			
		||||
 | 
			
		||||
type Theme struct {
 | 
			
		||||
	iconSet
 | 
			
		||||
	unpackedIcons bool
 | 
			
		||||
	icons            iconSet[theme.Icon]
 | 
			
		||||
	mimeIcons        iconSet[string]
 | 
			
		||||
	genericMimeIcons iconSet[string]
 | 
			
		||||
	appIcons         iconSet[string]
 | 
			
		||||
	genericAppIcons  iconSet[tomo.ApplicationRole]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Theme) RGBA (id theme.Color) (r, g, b, a uint32) {
 | 
			
		||||
@ -215,7 +230,67 @@ func (this *Theme) Apply (object tomo.Object, role theme.Role) event.Cookie {
 | 
			
		||||
		}
 | 
			
		||||
		box.SetBorder(border...)
 | 
			
		||||
		box.SetColor(buttonColor)
 | 
			
		||||
 | 
			
		||||
	case "Icon":
 | 
			
		||||
		switch role.Variant {
 | 
			
		||||
		case "small":  box.SetMinimumSize(image.Pt(16, 16))
 | 
			
		||||
		case "medium": box.SetMinimumSize(image.Pt(32, 32))
 | 
			
		||||
		case "large":  box.SetMinimumSize(image.Pt(48, 48))
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return event.MultiCookie()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Theme) Icon (id theme.Icon, size theme.IconSize) canvas.Texture {
 | 
			
		||||
	this.ensureIcons()
 | 
			
		||||
	return this.icons.Get(id, size)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Theme) MimeIcon (mime data.Mime, size theme.IconSize) canvas.Texture {
 | 
			
		||||
	this.ensureIcons()
 | 
			
		||||
	texture := this.mimeIcons.Get(mime.String(), size)
 | 
			
		||||
	if texture != nil {
 | 
			
		||||
		return texture
 | 
			
		||||
	} else {
 | 
			
		||||
		return this.genericMimeIcons.Get(mime.Type, size)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Theme) ApplicationIcon (id theme.ApplicationIcon, size theme.IconSize) canvas.Texture {
 | 
			
		||||
	this.ensureIcons()
 | 
			
		||||
	texture := this.appIcons.Get(id.Name, size)
 | 
			
		||||
	if texture != nil {
 | 
			
		||||
		return texture
 | 
			
		||||
	} else {
 | 
			
		||||
		return this.genericAppIcons.Get(id.Role, size)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *Theme) ensureIcons () {
 | 
			
		||||
	if this.unpackedIcons { return }
 | 
			
		||||
	this.unpackedIcons = true
 | 
			
		||||
 | 
			
		||||
	// this.icons.Init () // TODO
 | 
			
		||||
	this.mimeIcons.Init (
 | 
			
		||||
		nil, // TODO
 | 
			
		||||
		bytes.NewReader(mimeIconsMedium),
 | 
			
		||||
		nil, // TODO
 | 
			
		||||
		32, 12,
 | 
			
		||||
 | 
			
		||||
		// TODO
 | 
			
		||||
	)
 | 
			
		||||
	this.genericMimeIcons.Init (
 | 
			
		||||
		nil, // TODO
 | 
			
		||||
		bytes.NewReader(genericMimeIconsMedium),
 | 
			
		||||
		nil, // TODO
 | 
			
		||||
		1, 5,
 | 
			
		||||
 | 
			
		||||
		i(0, 0, "text"),
 | 
			
		||||
		i(1, 0, "image"),
 | 
			
		||||
		i(2, 0, "audio"),
 | 
			
		||||
		i(3, 0, "video"),
 | 
			
		||||
		i(4, 0, "application"),
 | 
			
		||||
	)
 | 
			
		||||
	// this.appIcons.Init () // TODO
 | 
			
		||||
	// this.genericAppIcons.Init () // TODO
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user