Icon no longer panics on nil texture

This commit is contained in:
Sasha Koshka 2023-09-05 13:04:06 -04:00
parent 67a0e09101
commit 59ca14cab6

View File

@ -1,5 +1,6 @@
package objects package objects
import "image"
import "git.tebibyte.media/tomo/tomo" import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/data" import "git.tebibyte.media/tomo/tomo/data"
import "git.tebibyte.media/tomo/tomo/theme" import "git.tebibyte.media/tomo/tomo/theme"
@ -41,7 +42,11 @@ func NewApplicationIcon (id theme.ApplicationIcon, size theme.IconSize) *Icon {
} }
func (this *Icon) SetTexture (texture canvas.Texture) { func (this *Icon) SetTexture (texture canvas.Texture) {
bounds := texture.Bounds()
this.Box.SetTexture(texture) this.Box.SetTexture(texture)
if texture == nil {
this.SetMinimumSize(image.Pt(0, 0))
} else {
bounds := texture.Bounds()
this.SetMinimumSize(bounds.Max.Sub(bounds.Min)) this.SetMinimumSize(bounds.Max.Sub(bounds.Min))
} }
}