Upgraded tomo version + added an Icon object
This commit is contained in:
parent
05b6490095
commit
d8d24632bb
2
go.mod
2
go.mod
@ -2,6 +2,6 @@ module git.tebibyte.media/tomo/objects
|
||||
|
||||
go 1.20
|
||||
|
||||
require git.tebibyte.media/tomo/tomo v0.26.1
|
||||
require git.tebibyte.media/tomo/tomo v0.27.0
|
||||
|
||||
require golang.org/x/image v0.11.0 // indirect
|
||||
|
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=
|
||||
|
47
icon.go
Normal file
47
icon.go
Normal file
@ -0,0 +1,47 @@
|
||||
package objects
|
||||
|
||||
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"
|
||||
|
||||
// Icon displays a single icon.
|
||||
type Icon struct {
|
||||
tomo.Box
|
||||
}
|
||||
|
||||
// NewIcon creates a new icon from an icon ID.
|
||||
func NewIcon (id theme.Icon, size theme.IconSize) *Icon {
|
||||
this := &Icon {
|
||||
Box: tomo.NewBox(),
|
||||
}
|
||||
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
||||
this.SetTexture(id.Texture(size))
|
||||
return this
|
||||
}
|
||||
|
||||
// NewMimeIcon creates a new icon from a MIME type.
|
||||
func NewMimeIcon (mime data.Mime, size theme.IconSize) *Icon {
|
||||
this := &Icon {
|
||||
Box: tomo.NewBox(),
|
||||
}
|
||||
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
||||
this.SetTexture(theme.MimeIcon(mime, size))
|
||||
return this
|
||||
}
|
||||
|
||||
// NewApplicationIcon creates a new icon from an application description.
|
||||
func NewApplicationIcon (id theme.ApplicationIcon, size theme.IconSize) *Icon {
|
||||
this := &Icon {
|
||||
Box: tomo.NewBox(),
|
||||
}
|
||||
theme.Apply(this, theme.R("objects", "Icon", size.String()))
|
||||
this.SetTexture(id.Texture(size))
|
||||
return this
|
||||
}
|
||||
|
||||
func (this *Icon) SetTexture (texture canvas.Texture) {
|
||||
bounds := texture.Bounds()
|
||||
this.Box.SetTexture(texture)
|
||||
this.SetMinimumSize(bounds.Max.Sub(bounds.Min))
|
||||
}
|
@ -16,4 +16,3 @@ func NewSeparator () *Separator {
|
||||
theme.Apply(this, theme.R("objects", "Separator", ""))
|
||||
return this
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user