Elements are now pass-scoped value handles: tests that read bounds after a frame bind a ui.Handle. pixel tells frames apart by the build pass's root, since the Tester clock no longer moves on its own. Fix the regressions the upgrade brought: - Clipboard reads in input handlers go through c.Services(). - MyGo notes an overlay's opener after building it, so AutoFocus inside lost it; pixel.AutoFocus focuses through a Handle, and archtest bans the raw call. Dialogs hand the focus back again. - Elements around a press stay hovered: Tooltip tells a press-given focus by focus arriving under the pointer. - The web host moves the Tester clock with real time, at most 500 ms a call, and gives components the real clock. The gallery's source index also accepts CRLF checkouts. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package fx
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type ConfettiOptions struct {
|
|
// Width and Height are dots; zeros mean 160 by 96.
|
|
Width, Height int
|
|
Label string
|
|
}
|
|
|
|
// confettiSlots color the bits in turn.
|
|
var confettiSlots = []pixel.Slot{pixel.Accent, pixel.Good, pixel.Warn, pixel.Bad, pixel.Info, pixel.Magic}
|
|
|
|
// Confetti tumbles bits of every color down, turning.
|
|
func Confetti(c *ui.Context, o ConfettiOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
w, h := size("Confetti", o.Width, o.Height, 160, 96)
|
|
return box(c, k, o.Label, w, h).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Clip(0, 0, g.W, g.H, func() { confetti(g, g.Step(10)) })
|
|
})
|
|
}
|
|
|
|
// confetti turns each bit flat, edge-on, upright, edge-on.
|
|
func confetti(g pixel.Canvas, step int) {
|
|
for i := range g.W * g.H / 90 {
|
|
speed := 1 + rnd(i, 90)%2
|
|
y := wrap(rnd(i, 91)+step*speed, g.H+4) - 2
|
|
x := wrap(rnd(i, 92)+sway(step+rnd(i, 93), 12, 1), g.W)
|
|
s := confettiSlots[i%len(confettiSlots)]
|
|
switch wrap(step+i, 4) {
|
|
case 0:
|
|
g.Rect(x, y, 2, 1, s)
|
|
case 2:
|
|
g.Rect(x, y, 1, 2, s)
|
|
default:
|
|
g.Dot(x, y, s)
|
|
}
|
|
}
|
|
}
|