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>
45 lines
1.4 KiB
Go
45 lines
1.4 KiB
Go
package game
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/feedback"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type LoadingTipsOptions struct {
|
|
// Width is in dots; zero means 200.
|
|
Width int
|
|
}
|
|
|
|
// tipTurn is how long a tip shows.
|
|
const tipTurn = 4 * time.Second
|
|
|
|
// LoadingTips turns tips every 4 s under a progress bar.
|
|
func LoadingTips(c *ui.Context, tips []string, value float64, o LoadingTipsOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
w := pixel.Or("LoadingTips Width", o.Width, 200)
|
|
if len(tips) == 0 {
|
|
panic("game: LoadingTips has no tips")
|
|
}
|
|
// Tips turn on the wall clock, like a loader's dots.
|
|
now := k.Now()
|
|
turn := now.Truncate(tipTurn)
|
|
k.At(c, turn.Add(tipTurn))
|
|
tip := tips[int(turn.Unix()/int64(tipTurn/time.Second))%len(tips)]
|
|
name := k.Msg("tip")
|
|
return ui.Column(c).Gap(k.D(6)).Width(k.D(w)).Children(func() {
|
|
feedback.Progress(c, k.Msg("loading"), value, feedback.ProgressOptions{Width: w - 4 - pixel.MicroWidth("100%"), Percent: true})
|
|
lines := pixel.Wrap(tip, w-tagW(name)-4, 3)
|
|
ui.Box(c).Role(ui.RoleStatus).Label(name+": "+tip).Size(k.D(w), k.D(len(lines)*pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
tag(g, 0, 3, name, pixel.Accent)
|
|
for i, l := range lines {
|
|
g.Text(tagW(name)+4, i*pixel.LineHeight, l, pixel.Faint, 1)
|
|
}
|
|
})
|
|
})
|
|
}
|