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>
58 lines
1.5 KiB
Go
58 lines
1.5 KiB
Go
package desk
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type wakeKey struct{}
|
|
|
|
// wake is input between frames; from is the first pointer.
|
|
type wake struct {
|
|
woke, seen bool
|
|
from [2]float32
|
|
}
|
|
|
|
// cover fills the window; keys, clicks, long moves end it.
|
|
func cover(c *ui.Context, k pixel.Kit, text string, open *bool, moves bool, draw func(g pixel.Canvas)) (anchor, panel ui.Element, woke bool) {
|
|
anchor = ui.Box(c).Role(ui.RoleNone)
|
|
st := ui.Local(anchor, wakeKey{}, func() wake { return wake{} })
|
|
was := *open
|
|
if st.woke {
|
|
*open = false
|
|
}
|
|
if !*open {
|
|
*st = wake{}
|
|
}
|
|
panel = ui.DialogBase(c, open, func(back, panel ui.Element) {
|
|
back.Draw(func(p *ui.Painter, r ui.Rect) { draw(k.Canvas(p, r)) })
|
|
back.HandleInput(func(ev ui.InputEvent) bool {
|
|
// Any button and the wheel end it, as keys do.
|
|
if ev.Kind == ui.InputPointerDown || ev.Kind == ui.InputScroll {
|
|
st.woke = true
|
|
}
|
|
if !moves || ev.Kind != ui.InputPointerMove {
|
|
return false
|
|
}
|
|
// The first move marks the spot; eight dots away wakes.
|
|
at := [2]float32{ev.X / k.Dot(), ev.Y / k.Dot()}
|
|
if !st.seen {
|
|
st.from, st.seen = at, true
|
|
}
|
|
if dx, dy := at[0]-st.from[0], at[1]-st.from[1]; dx*dx+dy*dy > 64 {
|
|
st.woke = true
|
|
}
|
|
return false
|
|
})
|
|
panel.Focusable().FocusRing(false).Label(text).HandleInput(func(ev ui.InputEvent) bool {
|
|
if ev.Kind == ui.InputKeyDown {
|
|
st.woke = true
|
|
return true
|
|
}
|
|
return false
|
|
})
|
|
})
|
|
return anchor, panel, was && !*open
|
|
}
|