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

40 lines
900 B
Go

package display
import (
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type BadgeOptions struct {
// Text replaces the count.
Text string
// Slot is the fill; zero means Bad.
Slot pixel.Slot
}
// Badge shows n, capped at 99+, or text.
func Badge(c *ui.Context, n int, o BadgeOptions) ui.Element {
k := pixel.K(c)
s := o.Text
if s == "" {
s = itoa(n)
if n > 99 {
s = "99+"
}
}
fill := slotOr(o.Slot, pixel.Bad)
if !pixel.MicroOK(s) {
w := pixel.Measure(s) + 6
return art(c, k, s, w, pixel.LineHeight+1, func(g pixel.Canvas) {
g.Frame(0, 0, w, pixel.LineHeight+1, pixel.Notched, fill)
g.Text(3, 0, s, pixel.AccentInk, 1)
})
}
w := max(pixel.MicroWidth(s)+6, 9)
return art(c, k, s, w, 9, func(g pixel.Canvas) {
g.Frame(0, 0, w, 9, pixel.Notched, fill)
g.Micro((w-pixel.MicroWidth(s))/2, 2, s, pixel.AccentInk, 1)
})
}