Added overloads to add an image to the Images container.
This commit is contained in:
parent
fe4a2b7b73
commit
eee707c4ec
21
ui/images.go
21
ui/images.go
@ -1,10 +1,14 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"image"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
"opslag.de/schobers/geom"
|
||||
)
|
||||
|
||||
type CreateImageFn func() (image.Image, error)
|
||||
|
||||
func ScaleImage(render Renderer, im Image, scale float32) Image {
|
||||
w := uint(im.Width() * scale)
|
||||
if w == 0 {
|
||||
@ -36,6 +40,23 @@ func (i *Images) AddImage(name string, im Image) {
|
||||
i.ims[name] = im
|
||||
}
|
||||
|
||||
func (i *Images) AddImageFn(name string, create CreateImageFn) error {
|
||||
im, err := create()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return i.AddImageNative(name, im)
|
||||
}
|
||||
|
||||
func (i *Images) AddImageNative(name string, im image.Image) error {
|
||||
m, err := i.render.CreateImage(im)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
i.AddImage(name, m)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Images) Destroy() {
|
||||
for _, im := range i.ims {
|
||||
im.Destroy()
|
||||
|
Loading…
Reference in New Issue
Block a user