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>
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package feedback
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type BusyOverlayOptions struct{}
|
|
|
|
type busyKey struct{}
|
|
|
|
// BusyOverlay veils busy content, whose controls then take no input.
|
|
func BusyOverlay(c *ui.Context, busy bool, o BusyOverlayOptions, content func()) ui.Element {
|
|
k := pixel.K(c)
|
|
outer := ui.Box(c)
|
|
// held is whether the veil had the focus last frame.
|
|
held := ui.Local(outer, busyKey{}, func() bool { return false })
|
|
if !busy && *held {
|
|
// From the root, parked controls inside take it back.
|
|
c.Root().Focus()
|
|
*held = false
|
|
}
|
|
if busy {
|
|
// Busy content is one Tab stop: the veil.
|
|
outer.FocusGroup(ui.Vertical)
|
|
}
|
|
return outer.Children(func() {
|
|
s := pixel.Current(c)
|
|
s.Inert = s.Inert || busy
|
|
before := c.Root().Focused()
|
|
var body ui.Element
|
|
pixel.Scope(c, s, func() { body = ui.Box(c).Children(content) })
|
|
if !busy {
|
|
return
|
|
}
|
|
veil := ui.Box(c).Absolute().Left(0).Top(0).Right(0).Bottom(0).Focusable().FocusRing(false).Role(ui.RoleProgress).Label(k.Msg("wait"))
|
|
if body.FocusWithin() || !before && c.Root().Focused() {
|
|
veil.Focus()
|
|
}
|
|
*held = veil.Focused()
|
|
focus := veil.FocusVisible()
|
|
veil.Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Checker(0, 0, g.W, g.H, pixel.Back)
|
|
// The spinner doubles in size where it fits.
|
|
sc := max(1, min(2, min(g.W, g.H)/14))
|
|
beads(g, (g.W-12*sc)/2, (g.H-12*sc)/2, sc)
|
|
if focus {
|
|
g.FocusMark(0, 0, g.W, g.H)
|
|
}
|
|
})
|
|
})
|
|
}
|