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

63 lines
1.6 KiB
Go

package input
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type RadioGroupOptions struct {
// Row lays the radios out across.
Row bool
Disabled bool
Label string
}
type radioKey struct{}
type RadioGroupResult struct {
Element ui.Element
Changed bool
}
// RadioGroup chooses *selected; one Tab stop, arrows choose.
func RadioGroup(c *ui.Context, labels []string, selected *int, o RadioGroupOptions) RadioGroupResult {
k := pixel.K(c)
var e ui.Element
if o.Row {
e = ui.Row(c).Gap(k.D(10)).FocusGroup(ui.Horizontal)
} else {
e = ui.Column(c).Gap(k.D(2)).FocusGroup(ui.Vertical)
}
res := RadioGroupResult{Element: e}
last := ui.Local(e, radioKey{}, func() int { return -1 })
focus := -1
e.Role(ui.RoleRadioGroup).Label(o.Label).Children(func() {
for i, l := range labels {
was := *selected == i
on := was
shell, base, st := pixel.Shell(c, func() ui.Element {
return ui.CheckboxBase(c, &on).Role(ui.RoleRadio).Label(l).Disabled(o.Disabled)
})
if base.Focused() {
focus = i
}
// Arrow moves show focus and choose; Tab entry does not.
moved := base.FocusVisible() && *last >= 0 && *last != i
if !was && (base.Changed() || moved) && !base.IsDisabled() {
*selected, res.Changed = i, true
}
shell.Size(k.D(12+pixel.Measure(l)), k.D(pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
dot(k.Canvas(p, r), l, *selected == i, st)
})
}
})
*last = focus
if res.Changed {
slog.Debug("8bit: radio group", "selected", *selected)
}
return res
}