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>
52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
package overlay
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type TitleCardOptions struct {
|
|
// Cue shows the card each time it changes.
|
|
Cue int
|
|
// Hold keeps the title up; zero means two seconds.
|
|
Hold time.Duration
|
|
}
|
|
|
|
// TitleCard dithers in, holds title, dithers out; fills its parent.
|
|
func TitleCard(c *ui.Context, title string, o TitleCardOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
if o.Hold < 0 {
|
|
panic("overlay: TitleCard Hold is negative")
|
|
}
|
|
hold := o.Hold
|
|
if hold == 0 {
|
|
hold = 2 * time.Second
|
|
}
|
|
e := ui.Box(c).Fill()
|
|
// Eight steps a second: four in, the hold, four out.
|
|
held := int(hold * 8 / time.Second)
|
|
step := k.Since(c, k.Cue(e, o.Cue), 8, held+8)
|
|
if step >= held+8 {
|
|
return e
|
|
}
|
|
level := 16
|
|
switch {
|
|
case k.Reduce():
|
|
case step < 4:
|
|
level = 4 * (step + 1)
|
|
case step >= held+4:
|
|
level = 4 * (held + 7 - step)
|
|
}
|
|
deep, light := dark(k)
|
|
return e.Role(ui.RoleStatus).Label(title).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Veil(0, 0, g.W, g.H, deep, level)
|
|
if level == 16 {
|
|
g.Text((g.W-pixel.Measure(title)*2)/2, (g.H-pixel.LineHeight*2)/2, title, light, 2)
|
|
}
|
|
})
|
|
}
|