objects/icon.go

36 lines
846 B
Go

package objects
import "git.tebibyte.media/tomo/tomo"
// Icon displays a single icon.
type Icon struct {
tomo.Box
}
func iconSizeString (size tomo.IconSize) string {
switch size {
case tomo.IconSizeLarge: return "large"
case tomo.IconSizeMedium: return "medium"
default: return "small"
}
}
// NewIcon creates a new icon from an icon ID.
func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
this.SetRole(tomo.R("objects", "Icon"))
this.SetIcon(icon, size)
return this
}
// SetIcon sets the icon.
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
iconTexture := icon.Texture(size)
bounds := iconTexture.Bounds()
this.SetAttr(tomo.AIcon(icon, size))
this.SetAttr(tomo.AMinimumSize(bounds.Dx(), bounds.Dy()))
this.SetTag(iconSizeString(size), true)
}