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>
116 lines
3.2 KiB
Go
116 lines
3.2 KiB
Go
package overlay
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/input"
|
|
)
|
|
|
|
const tooltipTestDelay = 150 * time.Millisecond
|
|
|
|
func tooltipTester(x, y float32) (*ui.Tester, *int) {
|
|
clicks := 0
|
|
tt := ui.NewTester(func(c *ui.Context) {
|
|
core.Use(c, core.Settings{})
|
|
ui.Column(c).Padding(y, 0, 0, x).Children(func() {
|
|
b := input.Button(c, "Share", input.ButtonOptions{})
|
|
if b.Clicked() {
|
|
clicks++
|
|
}
|
|
Tooltip(c, b, "Share with the court", TooltipOptions{Delay: tooltipTestDelay})
|
|
})
|
|
}, 400, 300)
|
|
return tt, &clicks
|
|
}
|
|
|
|
// waitTooltip waits until the tip shows, however slow the machine.
|
|
func waitTooltip(tt *ui.Tester) bool {
|
|
return overlayUntil(tt, func() bool { return tt.HasText("Share with the court") })
|
|
}
|
|
|
|
func TestTooltipHoverDelay(t *testing.T) {
|
|
tt, clicks := tooltipTester(40, 40)
|
|
r, _ := tt.Find("Share")
|
|
start := time.Now()
|
|
tt.Move(r.X+4, r.Y+4)
|
|
if time.Since(start) < tooltipTestDelay && tt.HasText("Share with the court") {
|
|
t.Fatal("tip showed before the delay")
|
|
}
|
|
waitTooltip(tt)
|
|
tip, ok := tt.Find("Share with the court")
|
|
if !ok || tip.Y < r.Y+r.H {
|
|
t.Fatalf("tip %+v ok %v below %+v", tip, ok, r)
|
|
}
|
|
tt.Move(400, 300)
|
|
tt.Frame()
|
|
if tt.HasText("Share with the court") {
|
|
t.Fatal("tip stayed after leave")
|
|
}
|
|
_ = tt.Click("Share")
|
|
if *clicks != 1 {
|
|
t.Fatalf("clicks %d", *clicks)
|
|
}
|
|
}
|
|
|
|
func TestTooltipFocusAndEscape(t *testing.T) {
|
|
tt, _ := tooltipTester(40, 40)
|
|
tt.Key(0, ui.KeyTab)
|
|
if !waitTooltip(tt) {
|
|
t.Fatal("no tip on keyboard focus")
|
|
}
|
|
tt.Key(0, ui.KeyEscape)
|
|
if tt.HasText("Share with the court") {
|
|
t.Fatal("Escape did not hide the tip")
|
|
}
|
|
tt.Advance(tooltipTestDelay + 30*time.Millisecond)
|
|
if tt.HasText("Share with the court") {
|
|
t.Fatal("tip came back while still focused")
|
|
}
|
|
}
|
|
|
|
func TestTooltipEdgeFlips(t *testing.T) {
|
|
tt, _ := tooltipTester(330, 262)
|
|
r, _ := tt.Find("Share")
|
|
tt.Move(r.X+4, r.Y+4)
|
|
waitTooltip(tt)
|
|
tip, ok := tt.Find("Share with the court")
|
|
if !ok || tip.Y > r.Y || tip.X+tip.W > 400 {
|
|
t.Fatalf("tip %+v not above and inside for anchor %+v", tip, r)
|
|
}
|
|
}
|
|
|
|
func TestTooltipScalesWithText(t *testing.T) {
|
|
widths := map[float32]float32{}
|
|
for _, scale := range []float32{1, 1.5} {
|
|
tt, _ := tooltipTester(20, 20)
|
|
tt.SetPreferences(ui.Preferences{TextScale: scale})
|
|
tt.Key(0, ui.KeyTab)
|
|
if !overlayUntil(tt, func() bool { return tt.HasText("Share with the court") }) {
|
|
t.Fatalf("scale %v: no tip", scale)
|
|
}
|
|
r, _ := tt.Find("Share with the court")
|
|
widths[scale] = r.W
|
|
}
|
|
if widths[1.5] < widths[1]*1.3 {
|
|
t.Fatalf("tip text width %v at 1.5x, %v at 1x: not scaled", widths[1.5], widths[1])
|
|
}
|
|
}
|
|
|
|
func TestTooltipSnapshot(t *testing.T) {
|
|
snapshotAfter(t, "tooltip", 360, 140, func(c *ui.Context) {
|
|
ui.Column(c).Padding(24).AlignItems(ui.Start).Children(func() {
|
|
b := input.Button(c, "Seal", input.ButtonOptions{Variant: input.Secondary})
|
|
Tooltip(c, b, "Seal the letter with wax", TooltipOptions{Delay: time.Millisecond})
|
|
})
|
|
}, func(tt *ui.Tester) {
|
|
tt.Key(0, ui.KeyTab)
|
|
if !overlayUntil(tt, func() bool { return tt.HasText("Seal the letter with wax") }) {
|
|
t.Fatal("tip did not show")
|
|
}
|
|
})
|
|
}
|