Checkpoint

This commit is contained in:
maze authored and maze committed 2026-10-29 17:29:54 +01:00
1 parent c5d6137fab
commit 4ae7655cd8
223 files changed
+14770 -18352

No files matched your search

+39 -23
View File
@@ -2,22 +2,25 @@ package widget
import (
"image"
"image/draw"
"sync"
"sync/atomic"
"github.com/sirupsen/logrus"
"github.com/BeatGlow/beatglow/app"
"github.com/BeatGlow/beatglow/draw"
"github.com/BeatGlow/beatglow/internal/safe"
)
type Base struct {
bounds safe.Rectangle
widget atomic.Pointer[app.Widget]
mu sync.RWMutex
buffer draw.Image
hidden bool
styles app.Styles
changed atomic.Bool
bounds safe.Rectangle
position safe.Point
widget atomic.Pointer[app.Widget]
mu sync.RWMutex
buffer draw.Image
visible bool
styles app.Styles
changed atomic.Bool
}
func (b *Base) Extend(w app.Widget) {
@@ -41,11 +44,8 @@ func (b *Base) Bounds() image.Rectangle {
}
func (b *Base) Move(p image.Point) app.Widget {
bounds := b.bounds.Load()
b.bounds.Store(image.Rectangle{
Min: p,
Max: bounds.Size(),
})
b.position.Store(p)
b.changed.Store(true)
return b.super()
}
@@ -57,42 +57,58 @@ func (b *Base) Resize(size image.Point) app.Widget {
}
func (b *Base) Hide(ctx app.Context) app.Widget {
log := logrus.WithField("widget", b.super())
if !b.IsVisible() {
log.Trace("widget is already invisible")
return b.super()
}
b.mu.Lock()
b.hidden = true
b.visible = false
b.mu.Unlock()
b.changed.Store(true)
if widget := b.super(); widget != nil {
widget.Refresh(ctx)
}
/*
if widget := b.super(); widget != nil {
log.Trace("widget refresh triggering")
widget.Refresh(ctx)
} else {
log.Trace("base: no super to refresh!")
}
*/
return b.super()
}
func (b *Base) Show(ctx app.Context) app.Widget {
log := logrus.WithField("widget", b.super())
if b.IsVisible() {
log.Trace("widget is already visible")
return b.super()
}
b.mu.Lock()
b.hidden = false
b.visible = true
b.mu.Unlock()
b.changed.Store(true)
if widget := b.super(); widget != nil {
widget.Refresh(ctx)
}
/*
if widget := b.super(); widget != nil {
log.Trace("widget refresh triggering")
widget.Refresh(ctx)
}
*/
return b.super()
}
func (b *Base) IsVisible() bool {
b.mu.RLock()
visible := !b.hidden
visible := b.visible
b.mu.RUnlock()
return visible
}
@@ -113,7 +129,7 @@ func (b *Base) SetStyles(styles app.Styles) app.Widget {
return b.super()
}
func (b *Base) Render(ctx app.Context) app.Widget {
func (b *Base) Refresh(ctx app.Context) app.Widget {
if !b.changed.CompareAndSwap(true, false) {
return b.super()
}