package objects 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. func NewIcon (id tomo.Icon, size tomo.IconSize) *Icon { this := &Icon { Box: tomo.NewBox(), } this.SetRole(tomo.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 tomo.IconSize) *Icon { this := &Icon { Box: tomo.NewBox(), } this.SetRole(tomo.R("objects", "Icon", size.String())) this.SetTexture(tomo.MimeIcon(mime, size)) return this } func (this *Icon) SetTexture (texture canvas.Texture) { this.Box.SetTextureCenter(texture) if texture == nil { this.SetMinimumSize(image.Pt(0, 0)) } else { bounds := texture.Bounds() this.SetMinimumSize(bounds.Max.Sub(bounds.Min)) } }