2023-09-04 00:32:04 -06:00
|
|
|
package objects
|
|
|
|
|
2023-09-05 11:04:06 -06:00
|
|
|
import "image"
|
2023-09-04 00:32:04 -06:00
|
|
|
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) {
|
|
|
|
this.Box.SetTexture(texture)
|
2023-09-05 11:04:06 -06:00
|
|
|
if texture == nil {
|
|
|
|
this.SetMinimumSize(image.Pt(0, 0))
|
|
|
|
} else {
|
|
|
|
bounds := texture.Bounds()
|
|
|
|
this.SetMinimumSize(bounds.Max.Sub(bounds.Min))
|
|
|
|
}
|
2023-09-04 00:32:04 -06:00
|
|
|
}
|