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:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-17 01:37:54 -04:00
1 parent bc716d27be
commit bcce34cda1
603 files changed
+1366 -1277

No files matched your search

+3 -3
View File
@@ -46,7 +46,7 @@ func Accordion(c *ui.Context, open *[]string, items []AccordionItem, opts Accord
focusTo := ui.Local(v.Element, "focus", func() int { return -1 })
v.Element.Children(func() {
for i, it := range items {
ui.Column(c).Key(it.ID).Children(func() {
ui.Column(c.Key(it.ID)).Children(func() {
if i > 0 {
ui.Box(c).Height(1).FillWidth().Background(k.Border)
}
@@ -75,7 +75,7 @@ func Accordion(c *ui.Context, open *[]string, items []AccordionItem, opts Accord
ui.Text(c, it.Title).FontWeight(600).Grow(1).MinWidth(0)
ui.Icon(c, icons.Must("chevron-down")).Size(16, 16).Rotate(180 * prog).TextColor(k.TextMuted).Shrink(0)
})
if panel := collapsiblePanel(c, isOpen, prog, it.Content); panel != nil {
if panel := collapsiblePanel(c, isOpen, prog, it.Content); panel.Valid() {
panel.Padding(0, u*4, u*4).Gap(u * 2)
}
})
@@ -85,7 +85,7 @@ func Accordion(c *ui.Context, open *[]string, items []AccordionItem, opts Accord
}
// accordionKey returns the header the arrows, Home or End move to from header i, or -1.
func accordionKey(tr *ui.Element, items []AccordionItem, i int) int {
func accordionKey(tr ui.Element, items []AccordionItem, i int) int {
step, from := 0, i
switch {
case tr.Shortcut(0, ui.KeyDown):
+1 -1
View File
@@ -22,7 +22,7 @@ type CardOptions struct {
const cardInset float32 = 4
// Card groups content on a surface with an outline. It adds no click behavior.
func Card(c *ui.Context, opts CardOptions, body func()) *ui.Element {
func Card(c *ui.Context, opts CardOptions, body func()) ui.Element {
k := core.Tokens(c)
u := core.Density(c).Unit()
pad := u * 4
+3 -3
View File
@@ -97,7 +97,7 @@ func Carousel(c *ui.Context, index *int, n int, opts CarouselOptions, slide func
ui.Column(c).Grow(1).MinWidth(0).FillHeight().Clip().Background(k.Surface).Border(theme.BorderWidth, k.Border).Radius(theme.CardRadius).
Role(ui.RoleGroup).Label(fmt.Sprintf(core.Msg(c, "carousel.position"), *index+1, n)).Children(func() {
if n > 0 {
ui.Column(c).Key(*index).Grow(1).Children(func() { slide(*index) })
ui.Column(c.Key(*index)).Grow(1).Children(func() { slide(*index) })
}
})
next := input.Button(c, "", input.ButtonOptions{Variant: input.Ghost, Icon: icons.Must("chevron-right"), Label: core.Msg(c, "carousel.next"), Disabled: n < 2 || !wrap && *index == n-1})
@@ -133,7 +133,7 @@ func Carousel(c *ui.Context, index *int, n int, opts CarouselOptions, slide func
}
// carouselDot is a position button: a filled diamond for the current slide.
func carouselDot(c *ui.Context, i, n int, on bool) *ui.Element {
func carouselDot(c *ui.Context, i, n int, on bool) ui.Element {
k := core.Tokens(c)
b := ui.ButtonBase(c).Size(theme.MinHitSize, theme.MinHitSize).Radius(theme.ControlRadius).
Label(fmt.Sprintf(core.Msg(c, "carousel.position"), i+1, n)).Role(ui.RoleTab).Selected(on)
@@ -154,7 +154,7 @@ func carouselDot(c *ui.Context, i, n int, on bool) *ui.Element {
}
// carouselPause is the pause button: two bars, or a play triangle while paused.
func carouselPause(c *ui.Context, paused bool) *ui.Element {
func carouselPause(c *ui.Context, paused bool) ui.Element {
k := core.Tokens(c)
label := core.Msg(c, "carousel.pause")
if paused {
+4 -8
View File
@@ -82,8 +82,7 @@ func TestCarouselKeyboard(t *testing.T) {
func TestCarouselNoAutoplayByDefault(t *testing.T) {
h := &carouselHarness{opts: CarouselOptions{Interval: 10 * time.Millisecond}}
tt := ui.NewTester(h.view, 420, 280)
time.Sleep(30 * time.Millisecond)
tt.Frame()
tt.Advance(30 * time.Millisecond)
if h.index != 0 || tt.HasText("Pause autoplay") {
t.Fatalf("advanced without Autoplay: %d", h.index)
}
@@ -92,8 +91,7 @@ func TestCarouselNoAutoplayByDefault(t *testing.T) {
func TestCarouselAutoplayPause(t *testing.T) {
h := &carouselHarness{opts: CarouselOptions{Autoplay: true, Interval: 20 * time.Millisecond}}
tt := ui.NewTester(h.view, 420, 280)
time.Sleep(30 * time.Millisecond)
tt.Frame()
tt.Advance(30 * time.Millisecond)
if h.index != 1 {
t.Fatalf("autoplay did not advance: %d", h.index)
}
@@ -102,8 +100,7 @@ func TestCarouselAutoplayPause(t *testing.T) {
tt.SetFocused(false)
tt.SetFocused(true)
at := h.index
time.Sleep(50 * time.Millisecond)
tt.Frame()
tt.Advance(50 * time.Millisecond)
if h.index != at || !tt.HasText("") {
t.Fatalf("paused carousel advanced: %d -> %d", at, h.index)
}
@@ -113,8 +110,7 @@ func TestCarouselAutoplayPause(t *testing.T) {
r, _ := tt.Find("Window " + fmt.Sprint(at+1))
_ = tt.Click("Resume autoplay")
tt.Move(r.X+2, r.Y+2) // hover pauses too
time.Sleep(50 * time.Millisecond)
tt.Frame()
tt.Advance(50 * time.Millisecond)
if h.index != at {
t.Fatalf("hovered carousel advanced: %d -> %d", at, h.index)
}
+4 -4
View File
@@ -55,7 +55,7 @@ func Collapsible(c *ui.Context, open *bool, opts CollapsibleOptions, content fun
ui.Text(c, opts.Title).FontWeight(600).SingleLine()
}
})
if panel := collapsiblePanel(c, *open, prog, content); panel != nil {
if panel := collapsiblePanel(c, *open, prog, content); panel.Valid() {
panel.Padding(u*2, u*2, u*2, u*8).Gap(u * 2)
}
})
@@ -73,13 +73,13 @@ func collapsibleTarget(open bool) float32 {
}
// collapsiblePanel builds fn while open or animating, clipped to its progress.
func collapsiblePanel(c *ui.Context, open bool, prog float32, fn func()) *ui.Element {
func collapsiblePanel(c *ui.Context, open bool, prog float32, fn func()) ui.Element {
if !open && prog == 0 {
return nil
return ui.Element{}
}
// Closing content takes no input or focus while it shrinks away.
clip := ui.Column(c).Shrink(0).Disabled(!open)
var inner *ui.Element
var inner ui.Element
clip.Children(func() {
inner = ui.Column(c).Shrink(0)
inner.Children(fn)
+1 -1
View File
@@ -89,7 +89,7 @@ func (s *DataTableState[K]) VisibleRows() (first, last int) { return s.rows.Visi
// DataTableView is a built DataTable and what happened to it in this frame.
type DataTableView struct {
Element *ui.Element
Element ui.Element
changed, submitted, sorted, retry bool
}
+2 -2
View File
@@ -43,12 +43,12 @@ func tableColumnMenu(c *ui.Context, cols []tableColumn, sort *ui.SortOrder, layo
}
}
}
ui.PopoverBase(c, b, open, func(panel *ui.Element) {
ui.PopoverBase(c, b, open, func(panel ui.Element) {
panel.Background(k.Surface).Border(theme.BorderWidth, k.ControlBorder).Radius(theme.PopupRadius).
Padding(u * 2).Gap(u).MinWidth(240).MarginY(u)
for at, id := range order {
col := cols[slices.IndexFunc(cols, func(col tableColumn) bool { return col.ID == id })]
ui.Row(c).Key(id).Gap(u).AlignItems(ui.Center).Children(func() {
ui.Row(c.Key(id)).Gap(u).AlignItems(ui.Center).Children(func() {
if hidden != nil {
tableVisibility(c, col, hidden, visible)
} else {
+1 -1
View File
@@ -33,7 +33,7 @@ type DescriptionListOptions struct {
// DescriptionListView is a built DescriptionList and what happened to it in this frame.
type DescriptionListView struct {
Element *ui.Element
Element ui.Element
copied int
}
+3 -3
View File
@@ -47,7 +47,7 @@ func ImageViewer(c *ui.Context, open *bool, index *int, images []ViewerImage) co
k := core.Tokens(c)
u := core.Density(c).Unit()
w, h := c.Size()
v.Element = ui.DialogBase(c, open, func(back, panel *ui.Element) {
v.Element = ui.DialogBase(c, open, func(back, panel ui.Element) {
back.Background(ui.RGBA(0, 0, 0, 0.55))
panel.Background(k.Surface).Border(theme.BorderWidth, k.Border).Radius(theme.PopupRadius).
Size(w-u*12, h-u*12).Padding(u * 3).Gap(u * 3).Label(core.Msg(c, "image_viewer.title"))
@@ -92,7 +92,7 @@ func ImageViewer(c *ui.Context, open *bool, index *int, images []ViewerImage) co
if tool("chevron-left", "image_viewer.prev", *index == 0) {
goTo(*index - 1)
}
stage := ui.Box(c).Grow(1).FillHeight().MinWidth(0).Focusable().AutoFocus().Clip().
stage := core.AutoFocus(c, ui.Box(c).Grow(1).FillHeight().MinWidth(0).Focusable()).Clip().
Radius(theme.ControlRadius).Background(k.Background).Role(ui.RoleImage).Label(img.Alt).Cursor(ui.CursorGrab)
internal.Ring(stage, k.Focus, theme.ControlRadius)
if dx, dy, ok := stage.Dragged(); ok {
@@ -143,7 +143,7 @@ func ImageViewer(c *ui.Context, open *bool, index *int, images []ViewerImage) co
}
// viewerKeys, anywhere in the panel, zooms with + - 0, switches with Left and Right, and pans with Shift+arrows.
func viewerKeys(panel *ui.Element, st *viewerState, zoom func(float32), goTo func(int), at int) {
func viewerKeys(panel ui.Element, st *viewerState, zoom func(float32), goTo func(int), at int) {
switch {
case panel.Shortcut(0, ui.KeyEqual), panel.Shortcut(ui.Shift, ui.KeyEqual):
zoom(viewerZoomStep)
+4 -4
View File
@@ -67,7 +67,7 @@ func (s *ListState[K]) ScrollTo(i int) {
// ListView is a built List and what happened to it in this frame.
type ListView struct {
Element *ui.Element
Element ui.Element
changed, submitted, retry bool
}
@@ -100,7 +100,7 @@ func List[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[
v.retry = DataPlaceholder(c, opts.Status, opts.Error, opts.Empty, core.Msg(c, "list.empty"))
return
}
var e *ui.Element
var e ui.Element
if opts.Grid {
e = listGrid(c, s, n, opts, item)
} else {
@@ -136,7 +136,7 @@ func listLocate[K comparable](s *ListState[K], n int, key func(int) K) {
slog.Debug("mujica: list selection moved", "row", s.cursor)
}
func listRows[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[K], item func(i int)) *ui.Element {
func listRows[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[K], item func(i int)) ui.Element {
d := core.Density(c)
s.Rows.Key = func(i int) any { return opts.Key(i) }
s.Rows.Label = opts.Label
@@ -159,7 +159,7 @@ func listRows[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOpti
}).Padding(d.Unit())
}
func listGrid[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[K], item func(i int)) *ui.Element {
func listGrid[K comparable](c *ui.Context, s *ListState[K], n int, opts ListOptions[K], item func(i int)) ui.Element {
d := core.Density(c)
w, h := opts.ItemWidth, opts.ItemHeight
if w <= 0 {
+1 -1
View File
@@ -29,7 +29,7 @@ type StatisticOptions struct {
}
// Statistic shows a headline number with its title, unit and change.
func Statistic(c *ui.Context, value float64, opts StatisticOptions) *ui.Element {
func Statistic(c *ui.Context, value float64, opts StatisticOptions) ui.Element {
if opts.Precision < 0 {
panic("mujica: Statistic with negative Precision")
}
+1 -1
View File
@@ -29,7 +29,7 @@ type TimelineItem struct {
}
// Timeline lists events top to bottom with markers joined by a line; long text wraps.
func Timeline(c *ui.Context, items []TimelineItem) *ui.Element {
func Timeline(c *ui.Context, items []TimelineItem) ui.Element {
k := core.Tokens(c)
u := core.Density(c).Unit()
return ui.Column(c).Role(ui.RoleList).Children(func() {
+1 -1
View File
@@ -162,7 +162,7 @@ func (t *treeCore[K]) itemStatus(c *ui.Context, item K, status func(K) DataStatu
// TreeView is a built Tree and what happened to it in this frame.
type TreeView struct {
Element *ui.Element
Element ui.Element
changed, submitted, retry bool
}