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

+45
View File
@@ -0,0 +1,45 @@
package chart_test
import (
"bytes"
"testing"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/chart"
)
func TestSpectrumPeaksStayWhenTheClockStepsBack(t *testing.T) {
clk, levels := newClock(), []float64{1}
tt := view(200, 100, clk, func(c *ui.Context) { chart.SpectrumBars(c, "EQ", levels, chart.SpectrumBarsOptions{}) })
levels[0] = 0
clk.t = clk.t.Add(200 * time.Millisecond)
tt.Frame()
before := bytes.Clone(tt.Image().Pix)
clk.t = clk.t.Add(-time.Hour)
tt.Frame()
// A peak flung an hour high would leave the box.
if !bytes.Equal(before, tt.Image().Pix) {
t.Fatal("the falling peak moved as the clock stepped back")
}
}
func TestSpectrumPeaksFallInWholeFrames(t *testing.T) {
clk, levels := newClock(), []float64{1}
tt := view(200, 400, clk, func(c *ui.Context) {
chart.SpectrumBars(c, "Peaks", levels, chart.SpectrumBarsOptions{Segments: 100})
})
levels[0] = 0
tt.Frame()
seen := map[string]bool{}
for range 7 {
seen[string(tt.Image().Pix)] = true
clk.t = clk.t.Add(10 * time.Millisecond)
tt.Frame()
}
// S5: 60 ms holds two pictures at most.
if len(seen) > 2 {
t.Fatalf("%d pictures in 60 ms", len(seen))
}
}
+3 -1
View File
@@ -30,10 +30,12 @@ func Legend(c *ui.Context, text string, series []Series, hidden []bool, o Legend
for i, s := range series {
shown := !hidden[i]
shell, base, st := pixel.Shell(c, func() *ui.Element { return ui.ToggleBase(c, &shown).Label(s.Name).Disabled(o.Disabled) })
if base.Changed() {
// The base turns before it learns it is off.
if base.Changed() && !base.IsDisabled() {
hidden[i], res.Changed = !shown, true
slog.Debug("8bit: legend", "label", text, "series", s.Name, "shown", shown)
}
shown = !hidden[i]
ink := pick(s.Slot, i)
shell.Size(k.D(10+pixel.Measure(s.Name)), k.D(pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
+4 -4
View File
@@ -37,9 +37,9 @@ func SpectrumBars(c *ui.Context, text string, levels []float64, o SpectrumBarsOp
if len(pk.at) != len(levels) {
pk.at = append([]float64(nil), levels...)
}
now := k.Now()
// A peak falls a bar a second; reduced, it rests.
fall := now.Sub(pk.last).Seconds()
// Peaks fall a bar a second, stepped; reduced, they rest.
now := k.Now().Truncate(time.Second / 15)
fall := max(0, now.Sub(pk.last).Seconds())
switch {
case pk.last.IsZero() || k.Reduce():
fall = 1
@@ -53,7 +53,7 @@ func SpectrumBars(c *ui.Context, text string, levels []float64, o SpectrumBarsOp
pk.moving = pk.moving || pk.at[i] > l
}
if pk.moving {
k.Tick(c, 20)
k.Tick(c, 15)
}
shown := append([]float64(nil), pk.at...)
return e.Draw(func(p *ui.Painter, r ui.Rect) {
+30
View File
@@ -0,0 +1,30 @@
package chart_test
import (
"fmt"
"testing"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/chart"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
func TestLegendKeyInAVeilsFirstFrameHidesNothing(t *testing.T) {
for _, veil := range []bool{false, true} {
hidden, inert := []bool{false, false}, false
tt := view(400, 200, newClock(), func(c *ui.Context) {
s := pixel.Current(c)
s.Inert = inert
pixel.Scope(c, s, func() {
chart.Legend(c, "Key", []chart.Series{{Name: "HP"}, {Name: "MP"}}, hidden, chart.LegendOptions{})
})
})
tt.Key(0, ui.KeyTab)
inert = veil
tt.Key(0, ui.KeySpace)
if hidden[0] == veil {
t.Errorf("veiled %v, Space left %v", veil, fmt.Sprint(hidden))
}
}
}