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>
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package media
|
|
|
|
import (
|
|
"math"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type VinylOptions struct {
|
|
Playing bool
|
|
}
|
|
|
|
// Vinyl turns a record while playing; the arm swings on.
|
|
func Vinyl(c *ui.Context, text string, o VinylOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
e := art(c, k, text, 72, 64)
|
|
swing := float64(k.Toward(c, e, o.Playing, 12, 6)) / 6
|
|
a := float64(turned(c, k, e, o.Playing, 8)%8) * math.Pi / 4
|
|
return e.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
body, line := dark(k)
|
|
g.Disc(32, 32, 29, body)
|
|
for _, rr := range []int{25, 21, 17, 13} {
|
|
g.Circle(32, 32, rr, line)
|
|
}
|
|
// Light stays put while the record turns under it.
|
|
g.Line(14, 17, 18, 13, pixel.Lit)
|
|
g.Line(46, 51, 50, 47, pixel.Lit)
|
|
g.Disc(32, 32, 9, pixel.Accent)
|
|
g.Rect(31+int(math.Round(5*math.Cos(a))), 31+int(math.Round(5*math.Sin(a))), 2, 2, pixel.AccentLit)
|
|
g.Disc(32, 32, 1, pixel.Lit)
|
|
// The arm swings from rest, 90°, onto grooves, 118°.
|
|
arm := (90 + 28*swing) * math.Pi / 180
|
|
hx, hy := 66+int(math.Round(30*math.Cos(arm))), 6+int(math.Round(30*math.Sin(arm)))
|
|
g.Line(66, 6, hx, hy, pixel.Edge)
|
|
g.Rect(hx-1, hy-1, 3, 3, pixel.Edge)
|
|
g.Disc(66, 6, 3, pixel.Edge)
|
|
g.Disc(66, 6, 2, pixel.Face)
|
|
})
|
|
}
|