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>
85 lines
2.4 KiB
Go
85 lines
2.4 KiB
Go
package chart
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
)
|
|
|
|
var scatterGroups = []ScatterGroup{
|
|
{Name: "Monks", Points: []ScatterPoint{{1, 2, 4}, {3, 5, 9}, {6, 4, 1}}},
|
|
{Name: "Nuns", Points: []ScatterPoint{{2, 7, 16}, {8, 9, 2}}},
|
|
}
|
|
|
|
func TestScatterChartKeyboardSelect(t *testing.T) {
|
|
var sel []ScatterKey
|
|
values := 0
|
|
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
|
r := ScatterChart(c, &sel, scatterGroups, ScatterChartOptions{Frame: ChartFrame{Label: "Choir"}, Bubbles: true})
|
|
if r.ValueChanged() {
|
|
values++
|
|
}
|
|
return r
|
|
}}
|
|
tt := ui.NewTester(h.view, 520, 420)
|
|
tabTo(t, tt, "Choir")
|
|
tt.Key(0, ui.KeyRight)
|
|
tt.Key(0, ui.KeyRight)
|
|
tt.Key(0, ui.KeySpace)
|
|
if fmt.Sprint(sel) != "[{0 1}]" || values != 1 {
|
|
t.Fatalf("Space selected %v (%d events)", sel, values)
|
|
}
|
|
if got := chartReadout(tt); got != "Monks · x 3 · y 5 · size 9 · selected" {
|
|
t.Fatalf("readout %q", got)
|
|
}
|
|
tt.Key(0, ui.KeyEnter)
|
|
if len(sel) != 0 {
|
|
t.Fatalf("Enter did not unselect: %v", sel)
|
|
}
|
|
}
|
|
|
|
func TestScatterChartBoxSelect(t *testing.T) {
|
|
var sel []ScatterKey
|
|
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
|
return ScatterChart(c, &sel, scatterGroups, ScatterChartOptions{Frame: ChartFrame{Label: "Choir"}})
|
|
}}
|
|
tt := ui.NewTester(h.view, 520, 420)
|
|
b := h.box(tt)
|
|
top := b.Y + 38
|
|
// Nice domains: x 0..10 over 52..W-12; y 0..10 over top+8..top+214.
|
|
x := func(v float32) float32 { return b.X + 52 + (b.W-64)*v/10 }
|
|
y := func(v float32) float32 { return top + 8 + 206*(1-v/10) }
|
|
tt.Press(x(0.5), y(6))
|
|
tt.Move(x(4), y(4))
|
|
tt.Move(x(6.5), y(1.5))
|
|
tt.Release(x(6.5), y(1.5))
|
|
if fmt.Sprint(sel) != "[{0 0} {0 1} {0 2}]" {
|
|
t.Fatalf("box chose %v", sel)
|
|
}
|
|
}
|
|
|
|
func TestScatterChartBad(t *testing.T) {
|
|
defer func() {
|
|
if recover() == nil {
|
|
t.Fatal("no panic for negative size")
|
|
}
|
|
}()
|
|
var sel []ScatterKey
|
|
ui.NewTester(func(c *ui.Context) {
|
|
core.Use(c, core.Settings{})
|
|
ScatterChart(c, &sel, []ScatterGroup{{Name: "a", Points: []ScatterPoint{{1, 1, -1}}}}, ScatterChartOptions{Frame: ChartFrame{Label: "x"}})
|
|
}, 300, 300)
|
|
}
|
|
|
|
func TestScatterChartSnapshot(t *testing.T) {
|
|
snapshot(t, "scatter_chart", 520, 340, func(c *ui.Context) {
|
|
sel := []ScatterKey{{1, 0}}
|
|
ui.Column(c).Padding(16).Children(func() {
|
|
ScatterChart(c, &sel, scatterGroups, ScatterChartOptions{Frame: ChartFrame{Label: "Choir"}, Bubbles: true})
|
|
})
|
|
})
|
|
}
|