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>
This commit is contained in:
1 parent
bc716d27be
commit
bcce34cda1
603 files changed
+1366
-1277
No files matched your search
+12
-12
@@ -39,7 +39,7 @@ type popupMenuLevel struct {
|
||||
}
|
||||
|
||||
type popupMenuSub struct {
|
||||
item *ui.Element
|
||||
item ui.Element
|
||||
seq int
|
||||
build func(m *PopupMenu)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func (m *PopupMenu) Item(label string, opts PopupMenuItemOptions) bool {
|
||||
// Check adds an item toggling *checked and reports whether it changed.
|
||||
func (m *PopupMenu) Check(label string, checked *bool, opts PopupMenuItemOptions) bool {
|
||||
// The base toggles as it is built, so a disabled wrapper comes first.
|
||||
var base *ui.Element
|
||||
var base ui.Element
|
||||
ui.Column(m.c).Shrink(0).Disabled(opts.Disabled).Children(func() { base = ui.CheckboxBase(m.c, checked) })
|
||||
it := m.row(base, opts.Disabled, false)
|
||||
m.content(it, label, *checked, false)
|
||||
@@ -109,7 +109,7 @@ func (m *PopupMenu) Separator() {
|
||||
}
|
||||
|
||||
// row styles an item element and runs the hover, focus and highlight logic.
|
||||
func (m *PopupMenu) row(it *ui.Element, disabled, sub bool) *ui.Element {
|
||||
func (m *PopupMenu) row(it ui.Element, disabled, sub bool) ui.Element {
|
||||
c := m.c
|
||||
k := core.Tokens(c)
|
||||
d := core.Density(c)
|
||||
@@ -123,7 +123,7 @@ func (m *PopupMenu) row(it *ui.Element, disabled, sub bool) *ui.Element {
|
||||
return it
|
||||
}
|
||||
if m.autofocus {
|
||||
it.AutoFocus()
|
||||
core.AutoFocus(c, it)
|
||||
m.autofocus = false
|
||||
}
|
||||
hovered := it.Hovered()
|
||||
@@ -146,7 +146,7 @@ func (m *PopupMenu) row(it *ui.Element, disabled, sub bool) *ui.Element {
|
||||
}
|
||||
|
||||
// content lays out the check column, label and submenu chevron of an item.
|
||||
func (m *PopupMenu) content(it *ui.Element, label string, checked, sub bool) {
|
||||
func (m *PopupMenu) content(it ui.Element, label string, checked, sub bool) {
|
||||
c := m.c
|
||||
k := core.Tokens(c)
|
||||
it.Children(func() {
|
||||
@@ -162,14 +162,14 @@ func (m *PopupMenu) content(it *ui.Element, label string, checked, sub bool) {
|
||||
}
|
||||
|
||||
// PopupMenuOpen shows the menu build fills below anchor while *open is true.
|
||||
func PopupMenuOpen(c *ui.Context, anchor *ui.Element, open *bool, build func(m *PopupMenu)) *ui.Element {
|
||||
func PopupMenuOpen(c *ui.Context, anchor ui.Element, open *bool, build func(m *PopupMenu)) ui.Element {
|
||||
if !*open {
|
||||
return nil
|
||||
return ui.Element{}
|
||||
}
|
||||
core.OverlayLayer(c, open)
|
||||
b := anchor.Bounds()
|
||||
root := &popupMenuRoot{}
|
||||
panel := ui.PopoverBase(c, anchor, open, func(panel *ui.Element) {
|
||||
panel := ui.PopoverBase(c, anchor, open, func(panel ui.Element) {
|
||||
core.OverlayStyle(c, panel, OverlayAnchored(c, panel, b))
|
||||
panel.Margin(4, 0, 0, 0).MinWidth(PopoverWide(c, max(b.W, 200))).MaxWidth(PopoverWide(c, 360)).MaxHeight(PopoverRoom(c, b))
|
||||
popupMenuLevelBuild(c, panel, root, build, true)
|
||||
@@ -188,7 +188,7 @@ func PopupMenuOpen(c *ui.Context, anchor *ui.Element, open *bool, build func(m *
|
||||
}
|
||||
|
||||
// popupMenuLevelBuild builds one level's items in outer, then its open submenu.
|
||||
func popupMenuLevelBuild(c *ui.Context, outer *ui.Element, root *popupMenuRoot, build func(m *PopupMenu), autofocus bool) {
|
||||
func popupMenuLevelBuild(c *ui.Context, outer ui.Element, root *popupMenuRoot, build func(m *PopupMenu), autofocus bool) {
|
||||
u := core.Density(c).Unit()
|
||||
// The padding leaves room for the items' focus rings inside the clipping scroll.
|
||||
items := ui.Scroll(c).Shrink(1).Padding(u + theme.FocusGap + theme.FocusWidth).FocusGroup(ui.Vertical)
|
||||
@@ -204,11 +204,11 @@ func popupMenuLevelBuild(c *ui.Context, outer *ui.Element, root *popupMenuRoot,
|
||||
}
|
||||
|
||||
// popupMenuSubmenu builds a submenu beside its item, flipped to stay in the window.
|
||||
func popupMenuSubmenu(c *ui.Context, outer *ui.Element, root *popupMenuRoot, lv *popupMenuLevel, s popupMenuSub) {
|
||||
func popupMenuSubmenu(c *ui.Context, outer ui.Element, root *popupMenuRoot, lv *popupMenuLevel, s popupMenuSub) {
|
||||
u := core.Density(c).Unit()
|
||||
ob, ib := outer.Bounds(), s.item.Bounds()
|
||||
ww, wh := c.Size()
|
||||
box := ui.Column(c).Absolute().Key(s.seq).MinWidth(min(180, ww-8)).MaxWidth(min(360, ww-8))
|
||||
box := ui.Column(c.Key(s.seq)).Absolute().MinWidth(min(180, ww-8)).MaxWidth(min(360, ww-8))
|
||||
sb := box.Bounds()
|
||||
left, top := ib.X+ib.W+u-ob.X, ib.Y-u-ob.Y
|
||||
if ob.X+left+sb.W > ww-4 {
|
||||
@@ -232,7 +232,7 @@ func popupMenuSubmenu(c *ui.Context, outer *ui.Element, root *popupMenuRoot, lv
|
||||
}
|
||||
|
||||
// popupMenuTrigger styles a menu trigger button with a trailing chevron.
|
||||
func popupMenuTrigger(c *ui.Context, b *ui.Element, label string, icon *ui.SVG, open bool) {
|
||||
func popupMenuTrigger(c *ui.Context, b ui.Element, label string, icon *ui.SVG, open bool) {
|
||||
k := core.Tokens(c)
|
||||
d := core.Density(c)
|
||||
b.MinHeight(d.ControlHeight()).MinWidth(theme.MinHitSize).Padding(0, d.Unit()*3, 0, d.Unit()*4).
|
||||
|
||||
Reference in new issue
Block a user