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>
28 lines
827 B
Go
28 lines
827 B
Go
package fx
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type ScreenShakeOptions struct {
|
|
// Cue shakes the content each time it changes.
|
|
Cue int
|
|
// Amount is the widest jolt in dots; zero means 3.
|
|
Amount int
|
|
}
|
|
|
|
// quakes are the jolts, a step each, in Amount thirds.
|
|
var quakes = [...][2]int{{3, -2}, {-3, 2}, {2, 3}, {-3, -2}, {2, 1}, {-1, -2}, {1, 1}, {-1, 0}, {0, 0}}
|
|
|
|
// ScreenShake jolts its content both ways, settling as it goes.
|
|
func ScreenShake(c *ui.Context, o ScreenShakeOptions, content func()) ui.Element {
|
|
k := pixel.K(c)
|
|
a := pixel.Or("ScreenShake Amount", o.Amount, 3)
|
|
e := ui.Box(c)
|
|
q := quakes[k.Shot(c, e, o.Cue, 15, len(quakes)-1)]
|
|
dx, dy := q[0]*a/3, q[1]*a/3
|
|
return e.Padding(k.D(a+dy), k.D(a-dx), k.D(a-dy), k.D(a+dx)).Children(content)
|
|
}
|