Files
beatglow/app/widget/image.go
T
2026-10-29 17:29:41 +01:00

50 lines
724 B
Go

package widget
import (
"image"
"github.com/BeatGlow/beatglow/app"
)
type Image struct {
Base
image image.Image
}
func NewImage(size image.Point) *Image {
w := new(Image)
w.Extend(w)
w.Resize(size)
return w
}
func (w *Image) String() string {
return "image:" + w.image.Bounds().String()
}
func (w *Image) Update(image image.Image) app.Widget {
w.mu.Lock()
w.image = image
w.mu.Unlock()
w.changed.Store(true)
return w
}
func (w *Image) Refresh(ctx app.Context) app.Widget {
if !w.IsVisible() {
return w
}
if !w.changed.CompareAndSwap(true, false) {
return w
}
w.mu.RLock()
app.ImageCopyBounds(ctx.Display(), w.image, w.Bounds())
w.mu.RUnlock()
return w
}
var _ app.Widget = (*Image)(nil)