Icon no longer embeds tomo.Box

This commit is contained in:
Sasha Koshka 2024-08-24 19:50:20 -04:00
parent c043f9bf8d
commit 697229d183

23
icon.go
View File

@ -3,9 +3,11 @@ package objects
import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/canvas"
var _ tomo.Object = new(Icon)
// Icon displays a single icon.
type Icon struct {
tomo.Box
box tomo.Box
icon tomo.Icon
size tomo.IconSize
}
@ -21,14 +23,19 @@ func iconSizeString (size tomo.IconSize) string {
// NewIcon creates a new icon from an icon ID.
func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
box: tomo.NewBox(),
}
this.SetRole(tomo.R("objects", "Icon"))
this.box.SetRole(tomo.R("objects", "Icon"))
this.SetIcon(icon, size)
this.OnIconSetChange(this.handleIconSetChange)
this.box.OnIconSetChange(this.handleIconSetChange)
return this
}
// GetBox returns the underlying box.
func (this *Icon) GetBox () tomo.Box {
return this.box
}
// SetIcon sets the icon.
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
if this.icon == icon { return }
@ -42,12 +49,12 @@ func (this *Icon) handleIconSetChange () {
}
func (this *Icon) 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)))
}
}