Compare commits
2 Commits
3127aad09a
...
b0672ec8ee
Author | SHA1 | Date | |
---|---|---|---|
b0672ec8ee | |||
961366b00a |
35
internal/faces/fallback/face.go
Normal file
35
internal/faces/fallback/face.go
Normal file
@ -0,0 +1,35 @@
|
||||
package fallbackFaces
|
||||
|
||||
import "golang.org/x/image/font"
|
||||
import "git.tebibyte.media/tomo/tomo"
|
||||
import "golang.org/x/image/font/basicfont"
|
||||
import "git.tebibyte.media/tomo/backend/style"
|
||||
|
||||
type faceSet struct {
|
||||
regular font.Face
|
||||
bold font.Face
|
||||
italic font.Face
|
||||
boldItalic font.Face
|
||||
}
|
||||
|
||||
// New creates a new fallback face set.
|
||||
func New () style.FaceSet {
|
||||
// TODO maybe pre-generate different variations of this face
|
||||
return &faceSet {
|
||||
regular: basicfont.Face7x13,
|
||||
bold: basicfont.Face7x13,
|
||||
italic: basicfont.Face7x13,
|
||||
boldItalic: basicfont.Face7x13,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *faceSet) Face (face tomo.Face) font.Face {
|
||||
bold := face.Weight >= 500
|
||||
italic := face.Italic >= 0.1 || face.Slant >= 0.1
|
||||
switch {
|
||||
case bold && italic: return this.boldItalic
|
||||
case bold: return this.bold
|
||||
case italic: return this.italic
|
||||
default: return this.regular
|
||||
}
|
||||
}
|
@ -412,23 +412,23 @@ func generateSource (data []byte, width int) map[tomo.Icon] canvas.Texture {
|
||||
return source
|
||||
}
|
||||
|
||||
type iconTheme struct {
|
||||
type iconSet struct {
|
||||
texturesSmall map[tomo.Icon] canvas.Texture
|
||||
texturesLarge map[tomo.Icon] canvas.Texture
|
||||
}
|
||||
|
||||
// New creates a new fallback icon theme.
|
||||
// New creates a new fallback icon set.
|
||||
func New () style.IconSet {
|
||||
return new(iconTheme)
|
||||
return new(iconSet)
|
||||
}
|
||||
|
||||
func (this *iconTheme) ensure () {
|
||||
func (this *iconSet) ensure () {
|
||||
if this.texturesSmall != nil { return }
|
||||
this.texturesSmall = generateSource(atlasSmallBytes, 16)
|
||||
this.texturesLarge = generateSource(atlasLargeBytes, 32)
|
||||
}
|
||||
|
||||
func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.Texture {
|
||||
func (this *iconSet) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.Texture {
|
||||
if size == tomo.IconSizeSmall {
|
||||
return this.texturesSmall
|
||||
} else {
|
||||
@ -436,7 +436,7 @@ func (this *iconTheme) selectSource (size tomo.IconSize) map[tomo.Icon] canvas.T
|
||||
}
|
||||
}
|
||||
|
||||
func (this *iconTheme) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
|
||||
func (this *iconSet) Icon (icon tomo.Icon, size tomo.IconSize) canvas.Texture {
|
||||
this.ensure()
|
||||
source := this.selectSource(size)
|
||||
if texture, ok := source[icon]; ok {
|
||||
@ -445,7 +445,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 *iconSet) MimeIcon (mime data.Mime, size tomo.IconSize) canvas.Texture {
|
||||
this.ensure()
|
||||
source := this.selectSource(size)
|
||||
if mime == data.M("inode", "directory") {
|
||||
|
Loading…
Reference in New Issue
Block a user