Files
ZacharyZhang-NYandClaude Opus 5.5 bcce34cda1 Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:

- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
  elements expire and Context methods are inert: read IsDisabled into a
  local during the build, keep a ui.Handle for Focus, use c.Services()
  for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
  content builds, so same-frame autofocus lost focus restore on close.
  It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
  c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
  split button tooltip no longer reorders its open menu; disabled
  menubar rows pass presses to the panel; Form defers blur-started
  async checks so the growing message no longer moves Submit away
  from the release; Combobox drops its disabled copy now that MyGo
  blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
  time.Sleep/time.Now and read element state inside the view. The web
  mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.

Snapshot goldens are darwin-only and were not re-verified here.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:37:54 -04:00

1.6 KiB
Raw Permalink Blame History

020 Kbd 快捷键

用途

把单键或组合键显示为键帽。按平台显示:macOS 用 ⌘ ⇧ ⌥ ⌃ 等符号且不加连接符;其他平台显示 Ctrl、Shift、Alt,键之间用“+”连接。只做展示,不注册快捷键。

最小示例

view := func(c *ui.Context) {
	core.Use(c, core.Settings{})
	ui.Row(c).Gap(6).Children(func() {
		display.Text(c, "Command palette", display.TextOptions{})
		display.Kbd(c, "Mod", "Shift", "P")
	})
}

参数

func Kbd(c *ui.Context, keys ...string) ui.Element

至少要传一个键,键名不能为空,否则 panic。键名不区分大小写:

键名 macOS 其他平台
Mod ⌘(Command) Ctrl
Ctrl ⌃ Ctrl
Alt ⌥(Option) Alt
Shift ⇧ Shift
Enter ↩ Enter
Esc esc Esc
Tab ⇥ Tab
Backspace ⌫ Backspace
Delete ⌦ Delete
Up Down Left Right ↑ ↓ ← → ↑ ↓ ← →

其他键名按原样显示;单个字符转为大写。

状态

纯展示。键帽随系统文本缩放放大,使用等宽字体、Surface 底色、ControlBorder 边框,底边 2 DIP。

事件

无。

键盘操作

不获取焦点,也不注册任何快捷键。辅助技术读出完整的组合键文字,例如“Command+Shift+P”或“Ctrl+Shift+P”。

限制

  • 平台在编译时由 runtime.GOOS 决定。Gallery 的网页镜像显示的是运行 Go 进程那台机器的平台。
  • Mod 与 MyGo 的 ui.Cmd 一致:macOS 上是 Command,其他平台是 Control。