Files
8bitMyGoUI/code/shortcutlist.go
T
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

49 lines
1.4 KiB
Go

package code
import (
"fmt"
"strings"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
)
// Shortcut is an action and its keys, pressed together.
type Shortcut struct {
Action string
Keys []string
}
type ShortcutListOptions struct {
// Width is in dots; zero means 220.
Width int
}
// ShortcutList pairs actions with their keycaps.
func ShortcutList(c *ui.Context, label string, items []Shortcut, o ShortcutListOptions) ui.Element {
k := pixel.K(c)
for _, it := range items {
if len(it.Keys) == 0 {
panic(fmt.Sprintf("code: ShortcutList action %q has no keys", it.Action))
}
}
return ui.Column(c).Width(k.D(pixel.Or("ShortcutList Width", o.Width, 220))).Gap(k.D(3)).Role(ui.RoleGroup).Label(label).Children(func() {
for _, it := range items {
ui.Row(c).FillWidth().Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleText).Label(it.Action + ", " + strings.Join(it.Keys, "+")).Children(func() {
pixel.Text(c, it.Action, pixel.TextOptions{}).Grow(1)
// Long chords wrap rather than run off the edge.
ui.Row(c).Wrap().Gap(k.D(2)).AlignItems(ui.Center).Children(func() {
for i, key := range it.Keys {
if i > 0 {
pixel.Text(c, "+", pixel.TextOptions{Slot: pixel.Faint})
}
text.Kbd(c, key, text.KbdOptions{})
}
})
})
}
})
}