Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:41 +01:00
1 parent 85a9ec684c
commit c5d6137fab
160 files changed
+76293 -387

No files matched your search

+78
View File
@@ -0,0 +1,78 @@
package widget
import (
"image"
"image/draw"
"github.com/BeatGlow/display"
)
// Empty display.
type Empty struct {
// Display this widget renders on.
Display display.Display
}
func (w Empty) Render(_ bool) bool {
w.Display.Clear()
return true
}
// Image displays an image.
type Image struct {
// Display this widget renders on.
Display display.Display
// Position on the display.
Position image.Point
// SourcePoint is the point from which this image is copied onto the display.
SourcePoint image.Point
// DrawOp is the drawing operation.
DrawOp draw.Op
buffer image.Image
changed bool
}
func NewImage(display display.Display, at image.Point, im image.Image) *Image {
return &Image{
Display: display,
Position: at,
DrawOp: draw.Src,
buffer: im,
}
}
func (w *Image) Set(i image.Image) {
w.buffer = i
w.changed = true
}
func (w *Image) Render(redraw bool) bool {
if !(redraw || w.changed) {
return false
}
if w.buffer != nil {
r := w.buffer.Bounds()
if w.Position.Eq(Center) {
b := w.buffer.Bounds().Size()
r.Min = image.Point{}
if x := r.Dx(); b.X < x {
r.Min.X = (x - b.X) / 2
}
if y := r.Dy(); b.Y < y {
r.Min.Y = (y - b.Y) / 2
}
} else {
r.Min = r.Min.Add(w.Position)
}
draw.Draw(w.Display, r, w.buffer, w.SourcePoint, w.DrawOp)
}
w.changed = false
return true
}