MimeIcon no longer embeds tomo.Box

This commit is contained in:
Sasha Koshka 2024-08-24 20:10:49 -04:00
parent ae74c3dbf4
commit 694f9127c0

View File

@ -4,22 +4,29 @@ import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/canvas"
var _ tomo.Object = new(MimeIcon)
// MimeIcon displays an icon of a MIME type.
type MimeIcon struct {
tomo.Box
box tomo.Box
mime data.Mime
size tomo.IconSize
}
// NewMimeIcon creates a new icon from a MIME type.
func NewMimeIcon (mime data.Mime, size tomo.IconSize) *MimeIcon {
this := &MimeIcon {
Box: tomo.NewBox(),
mimeIcon := &MimeIcon {
box: tomo.NewBox(),
}
this.SetRole(tomo.R("objects", "MimeIcon"))
this.SetIcon(mime, size)
this.OnIconSetChange(this.handleIconSetChange)
return this
mimeIcon.box.SetRole(tomo.R("objects", "MimeIcon"))
mimeIcon.SetIcon(mime, size)
mimeIcon.box.OnIconSetChange(mimeIcon.handleIconSetChange)
return mimeIcon
}
// GetBox returns the underlying box.
func (this *MimeIcon) GetBox () tomo.Box {
return this.box
}
// SetIcon sets the MIME type and size of the icon.
@ -35,12 +42,12 @@ func (this *MimeIcon) handleIconSetChange () {
}
func (this *MimeIcon) setTexture (texture canvas.Texture) {
this.SetAttr(tomo.ATexture(texture))
this.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
this.box.SetAttr(tomo.ATexture(texture))
this.box.SetAttr(tomo.ATextureMode(tomo.TextureModeCenter))
if texture == nil {
this.SetAttr(tomo.AMinimumSize(0, 0))
this.box.SetAttr(tomo.AMinimumSize(0, 0))
} else {
bounds := texture.Bounds()
this.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
this.box.SetAttr(tomo.AttrMinimumSize(bounds.Max.Sub(bounds.Min)))
}
}