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

2.0 KiB

084 Popover 弹出框

用途

在锚点下方显示可交互的面板;空间不足时翻到上方,并保持在窗口内。外部点击与 Escape 关闭。

最小示例

open := true
view := func(c *ui.Context) {
	core.Use(c, core.Settings{})
	b := input.Button(c, "Guests", input.ButtonOptions{Variant: input.Secondary})
	if b.Clicked() {
		open = !open
	}
	overlay.Popover(c, b, &open, overlay.PopoverOptions{Title: "Guest list"}, func() {
		ui.Text(c, "Twelve guests confirmed.")
	})
}
ui.Render(view, 400, 300, 1)

签名:func Popover(c *ui.Context, anchor ui.Element, open *bool, opts PopoverOptions, content func()) ui.Element。anchor 必须是本帧已构建的元素,nil 时 panic。

参数

字段 类型 默认值 含义
Title string "" 面板顶部的衬线标题,同时命名面板。
Width float32 0 固定宽度;0 时随内容,至少与锚点同宽,最多 360。
Label string "" 无标题时的无障碍名称。

状态

  • 6 DIP 圆角、Surface 底色、1 DIP 边框、160 ms 淡入。
  • 面板最高为锚点上下较大一侧的空间,超出时滚动。
  • 锚点首帧尚未布局时面板保持透明,避免闪到窗口左上角。

事件

外部点击与 Escape 把 *open 设为 false;内容内控件自行报告事件。

键盘操作

按键 行为
Tab 从锚点进入弹层,弹层元素紧跟锚点排序。
Escape 关闭并把焦点还给锚点。

限制

  • 打开期间外部点击只用于关闭,不传给下方控件:PopoverBase 用覆盖整窗的背板接收点击(ui/base.go:373)。
  • Escape 只关闭最上层的 MujicaUI 浮层(窗口内按打开顺序记录)。MyGo 自带的 ui.Popover、ui.Select 弹层不在这份记录中;它们打开在非模态 MujicaUI 浮层之上时,Escape 可能先关闭下面的 MujicaUI 浮层。
  • 只支持下方与上方两个位置(ui/widgets.go:689 keepInWindow);宽度不超过窗口,过高时内容滚动。