Checkpoint
This commit is contained in:
160 files changed
+76293
-387
No files matched your search
@@ -0,0 +1,49 @@
|
||||
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)
|
||||
Reference in new issue
Block a user