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>
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package overlay
|
||
|
||
import (
|
||
"strings"
|
||
"testing"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/input"
|
||
)
|
||
|
||
// overlayLongText is about 372 characters of description.
|
||
var overlayLongText = strings.Repeat("The east wing stays sealed until the court returns. ", 7)
|
||
|
||
// overlayInWindow fails unless every label lies fully inside a w×h window.
|
||
func overlayInWindow(t *testing.T, tt *ui.Tester, w, h float32, labels ...string) {
|
||
t.Helper()
|
||
for _, l := range labels {
|
||
r, ok := tt.Find(l)
|
||
if !ok || r.W == 0 || r.H == 0 || r.Y < 0 || r.X < 0 || r.Y+r.H > h || r.X+r.W > w {
|
||
t.Errorf("%q at %+v (found %v) outside the %v×%v window", l, r, ok, w, h)
|
||
}
|
||
}
|
||
}
|
||
|
||
func TestDialogActionsStayInWindowAtLargeText(t *testing.T) {
|
||
open, name := true, "Ophelia"
|
||
tt := ui.NewTester(func(c *ui.Context) {
|
||
core.Use(c, core.Settings{})
|
||
Dialog(c, &open, DialogOptions{Title: "Rename", Description: overlayLongText, Actions: func() {
|
||
input.Button(c, "Cancel", input.ButtonOptions{Variant: input.Secondary})
|
||
input.Button(c, "Save", input.ButtonOptions{})
|
||
}}, func() { ui.TextInput(c, &name) })
|
||
}, 800, 600)
|
||
tt.SetPreferences(ui.Preferences{TextScale: 2})
|
||
tt.Frame()
|
||
overlayInWindow(t, tt, 800, 600, "Cancel", "Save")
|
||
}
|
||
|
||
func TestAlertDialogActionsStayInWindowAtLargeText(t *testing.T) {
|
||
open := true
|
||
tt := ui.NewTester(func(c *ui.Context) {
|
||
core.Use(c, core.Settings{})
|
||
AlertDialog(c, &open, AlertDialogOptions{Title: "Burn?", Description: overlayLongText, ConfirmText: "letters"})
|
||
}, 800, 600)
|
||
tt.SetPreferences(ui.Preferences{TextScale: 2})
|
||
tt.Frame()
|
||
overlayInWindow(t, tt, 800, 600, "Cancel", "Delete", "Type “letters” to confirm")
|
||
}
|
||
|
||
func TestOverlayPanelFitsWindow(t *testing.T) {
|
||
for _, modal := range []bool{true, false} {
|
||
open := true
|
||
var panel ui.Rect
|
||
tt := ui.NewTester(func(c *ui.Context) {
|
||
core.Use(c, core.Settings{})
|
||
if p := Overlay(c, &open, OverlayOptions{Modal: modal}, func() {
|
||
ui.Text(c, strings.Repeat(overlayLongText, 6))
|
||
input.Button(c, "Done", input.ButtonOptions{})
|
||
}); p.Valid() {
|
||
panel = p.Bounds()
|
||
}
|
||
}, 600, 400)
|
||
tt.Frame()
|
||
if panel.X < 16 || panel.Y < 16 || panel.X+panel.W > 584 || panel.Y+panel.H > 384 {
|
||
t.Errorf("modal %v: panel %+v outside the window minus Inset", modal, panel)
|
||
}
|
||
}
|
||
}
|