objects/icon.go

42 lines
992 B
Go
Raw Normal View History

package objects
2023-09-05 11:04:06 -06:00
import "image"
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
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.
2024-05-26 15:21:58 -06:00
func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
2024-06-03 19:13:18 -06:00
this.SetRole(tomo.R("objects", "Icon", size.String()))
this.SetTexture(id.Texture(size))
return this
}
// NewMimeIcon creates a new icon from a MIME type.
2024-05-26 15:21:58 -06:00
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
2024-06-03 19:13:18 -06:00
this.SetRole(tomo.R("objects", "Icon", size.String()))
2024-05-26 15:21:58 -06:00
this.SetTexture(tomo.MimeIcon(mime, size))
return this
}
func (this *Icon) SetTexture (texture canvas.Texture) {
2024-05-26 15:21:58 -06:00
this.Box.SetTextureCenter(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))
}
}