objects/icon.go

36 lines
846 B
Go
Raw Normal View History

package objects
import "git.tebibyte.media/tomo/tomo"
// Icon displays a single icon.
type Icon struct {
tomo.Box
}
2024-07-21 09:48:28 -06:00
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.
2024-08-10 19:44:03 -06:00
func NewIcon (icon tomo.Icon, size tomo.IconSize) *Icon {
this := &Icon {
Box: tomo.NewBox(),
}
2024-07-21 09:48:28 -06:00
this.SetRole(tomo.R("objects", "Icon"))
2024-08-10 19:44:03 -06:00
this.SetIcon(icon, size)
return this
}
2024-08-10 19:44:03 -06:00
// SetIcon sets the icon.
func (this *Icon) SetIcon (icon tomo.Icon, size tomo.IconSize) {
2024-08-11 10:20:23 -06:00
iconTexture := icon.Texture(size)
bounds := iconTexture.Bounds()
2024-08-10 19:44:03 -06:00
this.SetAttr(tomo.AIcon(icon, size))
2024-08-11 10:20:23 -06:00
this.SetAttr(tomo.AMinimumSize(bounds.Dx(), bounds.Dy()))
2024-07-21 09:48:28 -06:00
this.SetTag(iconSizeString(size), true)
}