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

53 lines
1.3 KiB
Go

package input
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type ButtonGroupOptions struct {
Variant Variant
Size Size
Disabled bool
// Label names the group for assistive technology.
Label string
}
type ButtonGroupResult struct {
Element ui.Element
// Clicked is the button clicked this frame, or -1.
Clicked int
}
// ButtonGroup joins buttons as one Tab stop; arrows move.
func ButtonGroup(c *ui.Context, labels []string, o ButtonGroupOptions) ButtonGroupResult {
k := pixel.K(c)
h, pad, top, sc := o.Size.metrics()
res := ButtonGroupResult{Clicked: -1}
res.Element = ui.Row(c).Role(ui.RoleToolbar).Label(o.Label).FocusGroup(ui.Horizontal).Children(func() {
for i, l := range labels {
shell, base, st := pixel.Shell(c, func() ui.Element { return ui.ButtonBase(c).Label(l).Disabled(o.Disabled) })
w := pixel.Measure(l)*sc + 2*pad
if i > 0 {
shell.Margin(0, 0, 0, k.D(-1))
}
shell.Size(k.D(w), k.D(h)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
ink, dy := face(g, o.Variant, st, false)
g.Text(pad, top+dy, l, ink, sc)
g.Finish(st)
})
if base.Clicked() {
res.Clicked = i
}
}
})
if res.Clicked >= 0 {
slog.Debug("8bit: button group", "label", labels[res.Clicked])
}
return res
}