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

67 lines
1.5 KiB
Go

package navigation
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
var pointer = pixel.MustSprite(`
#..
##.
###
##.
#..
`)
type TocItem struct {
Title string
// Level indents sub-sections; zero is the top.
Level int
}
type TableOfContentsOptions struct {
// Width is in dots; zero means 160.
Width int
Disabled bool
}
type TableOfContentsResult struct {
Element ui.Element
Changed bool
}
// TableOfContents lists sections; ▶ marks the current one.
func TableOfContents(c *ui.Context, text string, items []TocItem, current *int, o TableOfContentsOptions) TableOfContentsResult {
k := pixel.K(c)
w := pixel.Or("TableOfContents Width", o.Width, 160)
res := TableOfContentsResult{}
// The bases turn before they learn they are off.
v := *current
res.Element = ui.RadioGroup(c, func() {
for i, it := range items {
shell, _, st := pixel.Shell(c, func() ui.Element {
return ui.RadioBase(c, &v, i).Label(it.Title).Disabled(o.Disabled)
})
shell.Size(k.D(w), k.D(pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
x, ink := 8+it.Level*10, pixel.Faint
if i == *current {
g.Sprite(x-6, 5, pointer, 0, pixel.Accent, 1)
ink = pixel.Accent
} else if st.Hover {
ink = pixel.Ink
}
g.Text(x, 0, it.Title, ink, 1)
g.Finish(st)
})
}
}).Gap(0).Label(text)
if res.Changed = keep(c, v, current, o.Disabled); res.Changed {
slog.Debug("8bit: toc", "label", text, "section", items[*current].Title)
}
return res
}