Audit keyboard, focus, veils, motion and clocks across all 500

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.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 16:03:04 -04:00
1 parent 81003b21ee
commit b4b4d67b92
198 files changed
+2708 -422

No files matched your search

+3 -1
View File
@@ -2,6 +2,7 @@ package datetime
import (
"math"
"time"
"github.com/egoist/mygo/ui"
@@ -17,8 +18,9 @@ type AnalogClockOptions struct {
func AnalogClock(c *ui.Context, o AnalogClockOptions) *ui.Element {
k := pixel.K(c)
size := pixel.Or("AnalogClock Size", o.Size, 48)
k.Tick(c, 1)
// Wake on the next whole second.
now := k.Now()
k.At(c, now.Truncate(time.Second).Add(time.Second))
h, m, s := now.Clock()
// hand ends at turn (0–1 from twelve) and length r.
hand := func(cx, cy int, turn float64, r int) (int, int) {
+4 -2
View File
@@ -2,6 +2,7 @@ package datetime
import (
"fmt"
"time"
"github.com/egoist/mygo/ui"
@@ -21,13 +22,14 @@ func DigitalClock(c *ui.Context, o DigitalClockOptions) *ui.Element {
if sc > 4 {
panic(fmt.Sprintf("datetime: DigitalClock Scale %d outside 1–4", sc))
}
k.Tick(c, 1)
// Wake on the next whole second.
now := k.Now()
k.At(c, now.Truncate(time.Second).Add(time.Second))
colon := func() {
ui.Box(c).Size(k.D(3*sc), k.D(11*sc)).Role(ui.RoleNone).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
// The colon blinks each half second, unless reduced.
if k.Reduce() || g.Step(2)%2 == 0 {
if k.Reduce() || g.Step(4)%4 < 2 {
g.Rect(sc, 3*sc, sc, sc, pixel.Bad)
g.Rect(sc, 7*sc, sc, sc, pixel.Bad)
}
+2 -2
View File
@@ -71,11 +71,11 @@ func month(c *ui.Context, text string, cur *time.Time, disabled, focus bool, mar
{ui.KeyPageUp, addMonths(*cur, -1)}, {ui.KeyPageDown, addMonths(*cur, 1)},
{ui.KeyHome, cur.AddDate(0, 0, 1-d)}, {ui.KeyEnd, addMonths(cur.AddDate(0, 0, 1-d), 1).AddDate(0, 0, -1)},
} {
if base.Shortcut(0, mv.key) {
if pixel.Shortcut(base, 0, mv.key) {
*cur = mv.to
}
}
enter, space := base.Shortcut(0, ui.KeyEnter), base.Shortcut(0, ui.KeySpace)
enter, space := pixel.Shortcut(base, 0, ui.KeyEnter), pixel.Shortcut(base, 0, ui.KeySpace)
picked = enter || space
first := time.Date(y, m, 1, 0, 0, 0, 0, cur.Location())
first = first.AddDate(0, 0, -int(first.Weekday()))
+4 -4
View File
@@ -35,15 +35,15 @@ func SeasonWheel(c *ui.Context, text string, season *pixel.Season, o SeasonWheel
shell, base, st := pixel.Shell(c, func() *ui.Element {
return ui.Box(c).Focusable().Role(ui.RoleRadioGroup).Label(text).Disabled(o.Disabled)
})
if base.Shortcut(0, ui.KeyRight) || base.Shortcut(0, ui.KeyDown) {
if pixel.Shortcut(base, 0, ui.KeyRight) || pixel.Shortcut(base, 0, ui.KeyDown) {
*season = (*season + 1) % 4
}
if base.Shortcut(0, ui.KeyLeft) || base.Shortcut(0, ui.KeyUp) {
if pixel.Shortcut(base, 0, ui.KeyLeft) || pixel.Shortcut(base, 0, ui.KeyUp) {
*season = (*season + 3) % 4
}
// Enter and Space are taken, so clicks come from pointers.
base.Shortcut(0, ui.KeyEnter)
base.Shortcut(0, ui.KeySpace)
pixel.Shortcut(base, 0, ui.KeyEnter)
pixel.Shortcut(base, 0, ui.KeySpace)
if base.Clicked() {
x, y, _ := base.PointerPosition()
*season = pixel.Season(quarter(int(x/k.Dot())-wheel/2, int(y/k.Dot())-wheel/2))
+1 -1
View File
@@ -43,7 +43,7 @@ func Stopwatch(c *ui.Context, text string, o StopwatchOptions) StopwatchResult {
running := !w.since.IsZero()
elapsed := w.banked
if running {
elapsed += now.Sub(w.since)
elapsed += k.Elapsed(&w.since)
k.Tick(c, 10)
}
res := StopwatchResult{Element: col}
+2 -2
View File
@@ -33,10 +33,10 @@ func SunDial(c *ui.Context, text string, hour *int, o SunDialOptions) SunDialRes
shell, base, st := pixel.Shell(c, func() *ui.Element {
return ui.Box(c).Focusable().Role(ui.RoleSlider).Label(text).Disabled(o.Disabled)
})
if base.Shortcut(0, ui.KeyLeft) {
if pixel.Shortcut(base, 0, ui.KeyLeft) {
*hour = (*hour + 23) % 24
}
if base.Shortcut(0, ui.KeyRight) {
if pixel.Shortcut(base, 0, ui.KeyRight) {
*hour = (*hour + 1) % 24
}
// The width spans the whole day, midnight to midnight.
+75
View File
@@ -0,0 +1,75 @@
package datetime_test
import (
"strings"
"testing"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/datetime"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
func TestKeysDoNotClickWhereThePointerRests(t *testing.T) {
day := time.Date(2026, 10, 12, 9, 30, 0, 0, time.UTC)
for name, tc := range map[string]struct {
build func(c *ui.Context, v *string)
// fx is where, across the control, the pointer rests.
fx float32
after ui.Key
}{
"WeekStrip": {func(c *ui.Context, v *string) {
d := day
datetime.WeekStrip(c, "Week", &d, datetime.WeekStripOptions{})
if !d.Equal(day) {
*v = d.Format("Jan 2")
}
}, 0.95, 0},
"SeasonWheel": {func(c *ui.Context, v *string) {
s := pixel.Spring
datetime.SeasonWheel(c, "Week", &s, datetime.SeasonWheelOptions{})
if s != pixel.Spring {
*v = "turned"
}
}, 0.9, 0},
"TimeInput": {func(c *ui.Context, v *string) {
tm := day
datetime.TimeInput(c, "Week", &tm, datetime.TimeInputOptions{})
// Up after the keys must step the hours.
if tm.Minute() != day.Minute() {
*v = tm.Format("15:04")
}
}, 0.9, ui.KeyUp},
} {
got := ""
tt := view(400, 300, newClock(), false, func(c *ui.Context) { tc.build(c, &got) })
r := find(t, tt, "Week")
tt.Move(r.X+r.W*tc.fx, r.Y+r.H/2)
tt.Key(0, ui.KeyTab)
tt.Key(0, ui.KeySpace)
tt.Key(0, ui.KeyEnter)
if tc.after != 0 {
tt.Key(0, tc.after)
}
if got != "" {
t.Errorf("%s: Space and Enter clicked where the pointer rests: %s", name, got)
}
}
}
func TestStopwatchHoldsWhenTheClockStepsBack(t *testing.T) {
clk := newClock()
tt := view(400, 200, clk, false, func(c *ui.Context) { datetime.Stopwatch(c, "Watch", datetime.StopwatchOptions{}) })
if err := tt.Click("START"); err != nil {
t.Fatal(err)
}
clk.t = clk.t.Add(-1200 * time.Millisecond)
tt.Frame()
if err := tt.Click("STOP"); err != nil {
t.Fatal(err)
}
if strings.Contains(strings.Join(tt.Texts(), " "), "-") {
t.Fatalf("a negative time: %q", tt.Texts())
}
}
+6 -6
View File
@@ -47,22 +47,22 @@ func TimeInput(c *ui.Context, text string, tm *time.Time, o TimeInputOptions) Ti
}
s.first = -1
}
if base.Shortcut(0, ui.KeyUp) {
if pixel.Shortcut(base, 0, ui.KeyUp) {
step(1)
}
if base.Shortcut(0, ui.KeyDown) {
if pixel.Shortcut(base, 0, ui.KeyDown) {
step(-1)
}
for _, mv := range []struct {
key ui.Key
seg int
}{{ui.KeyLeft, 0}, {ui.KeyRight, 1}} {
if base.Shortcut(0, mv.key) {
if pixel.Shortcut(base, 0, mv.key) {
s.seg, s.first = mv.seg, -1
}
}
for d := range 10 {
if !base.Shortcut(0, ui.Key0+ui.Key(d)) {
if !pixel.Shortcut(base, 0, ui.Key0+ui.Key(d)) {
continue
}
top := 23
@@ -86,8 +86,8 @@ func TimeInput(c *ui.Context, text string, tm *time.Time, o TimeInputOptions) Ti
}
}
// Enter and Space are taken, so clicks come from pointers.
base.Shortcut(0, ui.KeyEnter)
base.Shortcut(0, ui.KeySpace)
pixel.Shortcut(base, 0, ui.KeyEnter)
pixel.Shortcut(base, 0, ui.KeySpace)
if base.Clicked() {
x, _, _ := base.PointerPosition()
s.seg, s.first = 0, -1
+1 -1
View File
@@ -50,7 +50,7 @@ func Timer(c *ui.Context, text string, set *time.Duration, o TimerOptions) Timer
}
}
// It flashes for three seconds after ringing.
flash := !t.rang.IsZero() && now.Sub(t.rang) < 3*time.Second
flash := !t.rang.IsZero() && k.Elapsed(&t.rang) < 3*time.Second
if flash {
k.Tick(c, 4)
}
+4 -4
View File
@@ -29,16 +29,16 @@ func WeekStrip(c *ui.Context, text string, date *time.Time, o WeekStripOptions)
shell, base, st := pixel.Shell(c, func() *ui.Element {
return ui.Box(c).Focusable().Role(ui.RoleGroup).Label(text).Disabled(o.Disabled)
})
if base.Shortcut(0, ui.KeyLeft) {
if pixel.Shortcut(base, 0, ui.KeyLeft) {
*date = date.AddDate(0, 0, -1)
}
if base.Shortcut(0, ui.KeyRight) {
if pixel.Shortcut(base, 0, ui.KeyRight) {
*date = date.AddDate(0, 0, 1)
}
first := date.AddDate(0, 0, -int(date.Weekday()))
// Enter and Space are taken, so clicks come from pointers.
base.Shortcut(0, ui.KeyEnter)
base.Shortcut(0, ui.KeySpace)
pixel.Shortcut(base, 0, ui.KeyEnter)
pixel.Shortcut(base, 0, ui.KeySpace)
if base.Clicked() {
x, _, _ := base.PointerPosition()
if i := int(x / k.D(dayW)); x >= 0 && i < 7 {