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

79 lines
1.7 KiB
Go

package navigation
import (
"fmt"
"strings"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
// waving is a flag in two frames of wind.
var waving = pixel.MustSprite(`
.#..........
.#######....
.########...
.#########..
.########...
.#######....
.#..........
.#..........
.#..........
.#..........
.#..........
.##.#####...
.#########..
.#########..
.##########.
.##.#####...
.#..........
.#..........
.#..........
.#..........
`)
type StepsOptions struct{}
// Steps are flags on a path: done, waving, then locked.
func Steps(c *ui.Context, labels []string, current int, o StepsOptions) ui.Element {
k := pixel.K(c)
if current < 0 || current >= len(labels) {
panic(fmt.Sprintf("navigation: step %d of %d", current, len(labels)))
}
ws, total := make([]int, len(labels)), 0
for i, l := range labels {
ws[i] = max(pixel.Measure(l), 12) + 16
total += ws[i]
}
return ui.Box(c).Role(ui.RoleList).Label(strings.Join(labels, ", ")).Description(fmt.Sprintf("%d/%d", current+1, len(labels))).
Size(k.D(total), k.D(14+pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
x := 0
for i, l := range labels {
mid := x + ws[i]/2
if i > 0 {
for d := x - ws[i-1]/2 + 10; d < mid-8; d += 3 {
g.Dot(d, 6, pixel.Faint)
}
}
switch {
case i < current:
g.Sprite(mid-6, 0, waving, 0, pixel.Good, 1)
case i == current:
g.Sprite(mid-6, 0, waving, g.Step(4)%2, pixel.Accent, 1)
default:
g.Sprite(mid-6, 0, icon.Lock, 0, pixel.Faint, 1)
}
ink := pixel.Faint
if i <= current {
ink = pixel.Ink
}
g.Text(mid-pixel.Measure(l)/2, 14, l, ink, 1)
x += ws[i]
}
})
}