A cross-cutting pass, each fix with a test that failed first. Veils: MyGo still hands a key to a base that turned off this frame, so every element key now goes through pixel.Shortcut, which an archtest enforces. Input handlers record and the build applies them only while enabled; the editor turns away a veil-frame letter or copy; value bases get a copy and keep only enabled turns. Popups give a held focus back to their opener when the veil lifts. Motion: S5 is enforced at the clock. Every Tick, Since, Step, Toward and Shot runs at 4-15 fps; blinks keep 1 Hz on 4 fps steps, fast animations step at 15, and drawn time is quantized to frames. Clocks stepping back: Since holds at zero without overflow, and k.Elapsed moves a stored start to now, so nothing goes negative, runs backward or indexes out of range. Also: logs count typed text instead of holding it, gallery names use glyphs the font has, removable rows are keyed, components take their own Options (archtest), and sweeps over all 508 demos check veiled keys, clicks, wheels, the clock stepping back and names.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package navigation_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/navigation"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// veiled builds under a veil the test raises and lifts.
|
|
func veiled(inert *bool, build func(c *ui.Context)) *ui.Tester {
|
|
return view(600, 400, newClock(), false, func(c *ui.Context) {
|
|
s := pixel.Current(c)
|
|
s.Inert = *inert
|
|
pixel.Scope(c, s, func() { build(c) })
|
|
})
|
|
}
|
|
|
|
func TestOpenMenusGiveFocusBackAfterAVeil(t *testing.T) {
|
|
items := []navigation.MenuItem{{Label: "One"}, {Label: "Two"}}
|
|
for name, build := range map[string]func(c *ui.Context){
|
|
"dropdown": func(c *ui.Context) { navigation.DropdownMenu(c, "File", items, navigation.DropdownMenuOptions{}) },
|
|
"menubar": func(c *ui.Context) {
|
|
navigation.MenuBar(c, "Bar", []navigation.Menu{{Title: "Edit", Items: items}}, navigation.MenuBarOptions{})
|
|
},
|
|
} {
|
|
inert := false
|
|
tt := veiled(&inert, build)
|
|
tt.Key(0, ui.KeyTab)
|
|
tt.Key(0, ui.KeyDown)
|
|
if !tt.HasText("Two") {
|
|
t.Fatalf("%s did not open: %q", name, tt.Texts())
|
|
}
|
|
inert = true
|
|
tt.Frame()
|
|
inert = false
|
|
tt.Frame()
|
|
// Only focus on the opener lets Down open it again.
|
|
tt.Key(0, ui.KeyDown)
|
|
if !tt.HasText("Two") {
|
|
t.Errorf("%s did not get its focus back after the veil", name)
|
|
}
|
|
}
|
|
}
|