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

+88
View File
@@ -0,0 +1,88 @@
package widget
import (
"image"
"github.com/BeatGlow/beatglow/ui"
"github.com/BeatGlow/display"
"github.com/BeatGlow/display/draw"
"github.com/BeatGlow/display/pixel"
"github.com/sirupsen/logrus"
)
type Progress struct {
Display display.Display
Style ui.Style
Position image.Point
width int
height int
progress float64
buffer draw.Image
changed bool
}
func NewProgress(display display.Display, at image.Point, width, height int) *Progress {
logrus.WithFields(logrus.Fields{
"width": width,
"height": height,
"at": at,
}).Debug("new progress bar")
model := display.ColorModel()
w := &Progress{
Display: display,
Style: ui.StylesFor(model).Format,
Position: at,
width: width,
height: height,
buffer: ui.BufferFor(model, width, height),
}
w.Set(0)
return w
}
func (w *Progress) Set(progress float64) {
if progress < 0 {
progress = 0
}
if progress > 1 {
progress = 1
}
w.progress = progress
w.changed = true
}
func (w *Progress) SetStyle(style ui.Style) *Progress {
w.Style = style
return w
}
func (w *Progress) Render(redraw bool) bool {
if !(redraw || w.changed) {
return false
}
var stop = 1
if w.progress > 0 {
stop = 1 + int(float64(w.width-2)*w.progress+.5)
}
for y := 0; y < w.height; y++ {
for x := 0; x < w.width; x++ {
if ((x == 0 || x == w.width-1) && y != 0 && y != w.height-1) ||
((y == 0 || y == w.height-1) && x != 0 && x != w.width-1) {
//if (x != 0 && y == 0) || y == w.height-1 || x == 0 || x == w.width-1 || x < stop {
w.buffer.Set(x, y, w.Style.Foreground)
} else if x > 0 && x < stop {
w.buffer.Set(x, y, pixel.Gray4{Y: 0x77})
} else {
w.buffer.Set(x, y, w.Style.Background.At(x, y))
}
}
}
draw.Draw(w.Display, w.buffer.Bounds().Add(w.Position), w.buffer, image.Point{}, draw.Src)
w.changed = false
return true
}
var _ ui.Widget = (*Progress)(nil)