Overlays: review r1 fixes

This commit is contained in:
ZacharyZhang-NY committed 2026-10-05 12:59:33 -04:00
1 parent a27727bc71
commit e631f88cc0
41 files changed
+770 -278

No files matched your search

+34 -12
View File
@@ -7,7 +7,7 @@ import (
"github.com/egoist/mygo/ui"
)
const tooltipTestDelay = 20 * time.Millisecond
const tooltipTestDelay = 150 * time.Millisecond
func tooltipTester(x, y float32) (*ui.Tester, *int) {
clicks := 0
@@ -24,16 +24,17 @@ func tooltipTester(x, y float32) (*ui.Tester, *int) {
return tt, &clicks
}
func waitTooltip(tt *ui.Tester) {
time.Sleep(tooltipTestDelay + 10*time.Millisecond)
tt.Frame()
// 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 tt.HasText("Share with the court") {
if time.Since(start) < tooltipTestDelay && tt.HasText("Share with the court") {
t.Fatal("tip showed before the delay")
}
waitTooltip(tt)
@@ -41,7 +42,6 @@ func TestTooltipHoverDelay(t *testing.T) {
if !ok || tip.Y < r.Y+r.H {
t.Fatalf("tip %+v ok %v below %+v", tip, ok, r)
}
// The tip passes the pointer through: clicking it clicks what is below.
tt.Move(400, 300)
tt.Frame()
if tt.HasText("Share with the court") {
@@ -56,15 +56,15 @@ func TestTooltipHoverDelay(t *testing.T) {
func TestTooltipFocusAndEscape(t *testing.T) {
tt, _ := tooltipTester(40, 40)
tt.Key(0, ui.KeyTab)
waitTooltip(tt)
if !tt.HasText("Share with the court") {
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")
}
waitTooltip(tt)
time.Sleep(tooltipTestDelay + 30*time.Millisecond)
tt.Frame()
if tt.HasText("Share with the court") {
t.Fatal("tip came back while still focused")
}
@@ -81,11 +81,33 @@ func TestTooltipEdgeFlips(t *testing.T) {
}
}
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) {
snapshot(t, "tooltip", 360, 140, func(c *ui.Context) {
overlaySnapshot(t, "tooltip", 360, 140, func(c *ui.Context) {
ui.Column(c).Padding(24).AlignItems(ui.Start).Children(func() {
Button(c, "Seal", ButtonOptions{Variant: Secondary})
tooltipShow(c, ui.Rect{X: 24, Y: 24, W: 62, H: 36}, "Seal the letter with wax")
b := Button(c, "Seal", ButtonOptions{Variant: 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")
}
})
}