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>
72 lines
2.3 KiB
Go
72 lines
2.3 KiB
Go
package chart
|
||
|
||
import (
|
||
"testing"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
||
)
|
||
|
||
func TestBulletChartReadout(t *testing.T) {
|
||
target := 250.0
|
||
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
||
return BulletChart(c, 270, BulletChartOptions{Frame: ChartFrame{Label: "Alms"}, Target: &target, Bands: []float64{150, 225, 300}})
|
||
}}
|
||
tt := ui.NewTester(h.view, 520, 420)
|
||
tabTo(t, tt, "Alms")
|
||
want := []string{"Actual 270", "Target 250", "Range 1: 0–150", "Range 2: 150–225", "Range 3: 225–300"}
|
||
for i, w := range want {
|
||
tt.Key(0, ui.KeyRight)
|
||
if got := chartReadout(tt); got != w {
|
||
t.Fatalf("mark %d %q, want %q", i, got, w)
|
||
}
|
||
}
|
||
tt.Key(0, ui.KeyEscape)
|
||
b := h.box(tt)
|
||
plotW := b.W - 24
|
||
tt.Move(b.X+8+plotW*0.1, b.Y+6+21) // band 1, inside the value bar
|
||
if got := chartReadout(tt); got != "Actual 270" {
|
||
t.Fatalf("hover bar %q", got)
|
||
}
|
||
tt.Move(b.X+8+plotW*0.1, b.Y+8) // band 1, above the bar
|
||
if got := chartReadout(tt); got != "Range 1: 0–150" {
|
||
t.Fatalf("hover band %q", got)
|
||
}
|
||
}
|
||
|
||
func TestBulletChartVerticalAndBad(t *testing.T) {
|
||
h := &chartHarness{build: func(c *ui.Context) ChartResult {
|
||
return BulletChart(c, 40, BulletChartOptions{Frame: ChartFrame{Label: "Alms", Height: 200}, Vertical: true, Max: 100})
|
||
}}
|
||
tt := ui.NewTester(h.view, 520, 420)
|
||
b := h.box(tt)
|
||
tt.Move(b.X+b.W/2, b.Y+8+184*0.8) // low on the scale: inside the bar
|
||
if got := chartReadout(tt); got != "Actual 40" {
|
||
t.Fatalf("vertical hover %q", got)
|
||
}
|
||
defer func() {
|
||
if recover() == nil {
|
||
t.Fatal("no panic for unsorted bands")
|
||
}
|
||
}()
|
||
ui.NewTester(func(c *ui.Context) {
|
||
core.Use(c, core.Settings{})
|
||
BulletChart(c, 1, BulletChartOptions{Frame: ChartFrame{Label: "x"}, Bands: []float64{5, 2}})
|
||
}, 300, 300)
|
||
}
|
||
|
||
func TestBulletChartSnapshot(t *testing.T) {
|
||
target := 250.0
|
||
snapshot(t, "bullet_chart", 520, 300, func(c *ui.Context) {
|
||
ui.Row(c).Padding(16).Gap(16).Children(func() {
|
||
ui.Column(c).Width(360).Children(func() {
|
||
BulletChart(c, 270, BulletChartOptions{Frame: ChartFrame{Label: "Alms"}, Target: &target, Bands: []float64{150, 225, 300}})
|
||
})
|
||
ui.Column(c).Width(100).Children(func() {
|
||
BulletChart(c, 40, BulletChartOptions{Frame: ChartFrame{Label: "Oil", Height: 200}, Vertical: true, Target: &[]float64{70}[0], Bands: []float64{50, 80, 100}})
|
||
})
|
||
})
|
||
})
|
||
}
|