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>
1.7 KiB
1.7 KiB
085 Tooltip 文字提示
用途
指针停留或键盘聚焦一段时间后,在元素旁显示简短说明。提示不含交互内容,不拦截指针,并作为元素的无障碍描述。
最小示例
view := func(c *ui.Context) {
core.Use(c, core.Settings{})
b := input.Button(c, "Seal", input.ButtonOptions{})
overlay.Tooltip(c, b, "Seal the letter with wax", overlay.TooltipOptions{})
}
ui.Render(view, 400, 300, 1)
签名:func Tooltip(c *ui.Context, anchor ui.Element, text string, opts TooltipOptions) ui.Element,返回 anchor。anchor 为 nil 时 panic;text 为空时什么也不做。
参数
| 字段 | 类型 | 默认值 | 含义 |
|---|---|---|---|
Delay |
time.Duration |
500 ms | 悬停或键盘聚焦持续多久后显示;负数 panic。 |
状态
- 炭黑底(深色主题为象牙底)、2 DIP 圆角、12+1 DIP 文字,最宽 240 DIP 后换行。
- 默认在元素下方居中,下方放不下时翻到上方,左右限制在窗口内。
事件
无业务事件。text 同时写入 anchor 的无障碍描述。
键盘操作
| 按键 | 行为 |
|---|---|
| Tab 聚焦 | 键盘焦点停留 Delay 后显示。 |
| Escape | 隐藏,直到指针离开或焦点移走。 |
限制
- Escape 只关闭最上层的 MujicaUI 浮层(窗口内按打开顺序记录)。MyGo 自带的
ui.Popover、ui.Select弹层不在这份记录中;它们打开在非模态 MujicaUI 浮层之上时,Escape 可能先关闭下面的 MujicaUI 浮层。 - 只在键盘焦点(可见焦点)时显示,鼠标点击获得的焦点不触发。
- 不使用 MyGo 的
Element.Tooltip:它只跟随指针、不响应焦点(ui/widgets.go:549)。