Files
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
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>
2026-10-17 01:31:08 -04:00

46 lines
1.3 KiB
Go

package game
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type ScoreBoardOptions struct {
// Digits pads both scores; zero means 6.
Digits int
}
// ScoreBoard shows SCORE and HI-SCORE in big digits.
func ScoreBoard(c *ui.Context, score, hi int, o ScoreBoardOptions) ui.Element {
k := pixel.K(c)
if score < 0 || hi < 0 {
panic(fmt.Sprintf("game: ScoreBoard %d and %d", score, hi))
}
digits := pixel.Or("ScoreBoard Digits", o.Digits, 6)
// A score past the best becomes the best, lit.
best, beat := max(hi, score), score > hi
cols := []struct {
name, n string
ink pixel.Slot
}{{k.Msg("score"), fmt.Sprintf("%0*d", digits, score), pixel.Faint}, {k.Msg("hi_score"), fmt.Sprintf("%0*d", digits, best), pixel.Faint}}
if beat {
cols[1].ink = pixel.Warn
}
w, top := 0, 0
for _, col := range cols {
w, top = max(w, tagW(col.name), 2*pixel.Measure(col.n)), max(top, tagH(col.name)+2)
}
label := fmt.Sprintf("%s %d, %s %d", cols[0].name, score, cols[1].name, best)
return ui.Box(c).Role(ui.RoleText).Label(label).Size(k.D(2*w+16), k.D(top+2*pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
for i, col := range cols {
x := i * (w + 16)
tag(g, x, 0, col.name, col.ink)
g.Text(x, top-2, col.n, pixel.Ink, 2)
}
})
}