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 -3
View File
@@ -9,16 +9,16 @@ import (
type BlinkTextOptions struct {
Slot pixel.Slot
Scale int
// FPS is blinks per second, times two; zero means 2.
// FPS steps a four-step blink, 4–15; zero means 4.
FPS int
}
// BlinkText blinks; under Reduce Motion it stays shown.
func BlinkText(c *ui.Context, s string, o BlinkTextOptions) *ui.Element {
k, sc := pixel.K(c), scale(o.Scale)
fps := pixel.Or("BlinkText FPS", o.FPS, 2)
fps := pixel.Or("BlinkText FPS", o.FPS, 4)
return block(c, k, s, pixel.Measure(s)*sc, pixel.LineHeight*sc, func(g pixel.Canvas) {
if g.Step(fps)%2 == 0 {
if g.Step(fps)%4 < 2 {
g.Text(0, 0, s, o.Slot, sc)
}
})
+2 -2
View File
@@ -25,9 +25,9 @@ func Marquee(c *ui.Context, s string, o MarqueeOptions) *ui.Element {
if k.Reduce() || e.Hovered() {
ms.last = -1
} else {
step := k.Tick(c, 20)
step := k.Tick(c, 15)
if ms.last >= 0 {
ms.offset += step - ms.last
ms.offset += max(0, step-ms.last)
}
ms.last = step
}
+68
View File
@@ -0,0 +1,68 @@
package text_test
import (
"bytes"
"fmt"
"strings"
"testing"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/text"
)
func TestTypewriterKeepsItsSpeedOnS5Steps(t *testing.T) {
clk, done := newClock(), 0
tt := view(400, 100, clk, func(c *ui.Context) {
// Twenty letters at the default twenty a second.
if text.Typewriter(c, "ABCDEFGHIJKLMNOPQRST", text.TypewriterOptions{}).Done {
done++
}
})
clk.add(900 * time.Millisecond)
tt.Frame()
if done != 0 {
t.Fatal("the text was out early")
}
clk.add(150 * time.Millisecond)
tt.Frame()
if done != 1 {
t.Fatal("the text was not out after a second")
}
}
func TestTextAnimationsSurviveTheClockSteppingBack(t *testing.T) {
clk := newClock()
tt := view(400, 200, clk, func(c *ui.Context) {
text.Typewriter(c, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", text.TypewriterOptions{})
text.ScrambleText(c, "SCRAMBLED EGGS", text.ScrambleTextOptions{})
text.Marquee(c, "HELLO WORLD", text.MarqueeOptions{Width: 40})
})
for _, d := range []time.Duration{200 * time.Millisecond, -time.Hour, 200 * time.Millisecond} {
clk.add(d)
tt.Frame()
}
}
func TestMarqueeHoldsWhenTheClockStepsBack(t *testing.T) {
clk := newClock()
tt := view(400, 100, clk, func(c *ui.Context) { text.Marquee(c, "HELLO WORLD", text.MarqueeOptions{Width: 60}) })
clk.add(time.Second)
tt.Frame()
before := bytes.Clone(tt.Image().Pix)
clk.add(-time.Hour)
tt.Frame()
if !bytes.Equal(before, tt.Image().Pix) {
t.Fatal("the marquee ran backward as the clock stepped back")
}
}
func TestTypingSpeedsHaveACeiling(t *testing.T) {
defer func() {
if r := fmt.Sprint(recover()); !strings.HasPrefix(r, "text: Typewriter CPS") {
t.Fatalf("CPS 1001 gave %q", r)
}
}()
view(400, 100, newClock(), func(c *ui.Context) { text.Typewriter(c, "HI", text.TypewriterOptions{CPS: 1001}) })
}
+2 -2
View File
@@ -11,7 +11,7 @@ const scrambleRunes = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789#$%&*+?"
type ScrambleTextOptions struct {
Slot pixel.Slot
Scale int
// FPS is zero for 30; two steps settle a character.
// FPS is 4–15, zero for 15; two steps settle one.
FPS int
}
@@ -25,7 +25,7 @@ type scrambleState struct {
// ScrambleText settles from random glyphs to s, left to right.
func ScrambleText(c *ui.Context, s string, o ScrambleTextOptions) *ui.Element {
k, sc := pixel.K(c), scale(o.Scale)
fps := pixel.Or("ScrambleText FPS", o.FPS, 30)
fps := pixel.Or("ScrambleText FPS", o.FPS, 15)
rs := []rune(s)
e := ui.Box(c).Size(k.D(pixel.Measure(s)*sc), k.D(pixel.LineHeight*sc)).Label(s).Role(ui.RoleText)
st := ui.Local(e, scrambleKey{}, func() scrambleState { return scrambleState{start: -1} })
+5 -4
View File
@@ -223,17 +223,18 @@ func TestMarqueeScrollsAndPauses(t *testing.T) {
}
return -1
}
// Steps come at 15 a second, a dot each.
r0 := last()
clk.add(500 * time.Millisecond)
clk.add(10 * time.Second / 15)
tt.Frame()
r1 := last()
tt.Move(10, 10)
clk.add(500 * time.Millisecond)
clk.add(10 * time.Second / 15)
tt.Frame()
r2 := last()
tt.Move(300, 90)
tt.Frame()
clk.add(250 * time.Millisecond)
clk.add(5 * time.Second / 15)
tt.Frame()
if r3 := last(); r0 < 0 || r0-r1 != 10 || r2 != r1 || r1-r3 != 5 {
t.Fatalf("ends at %d, %d (10 steps), %d (hovered), %d (5 more)", r0, r1, r2, r3)
@@ -371,7 +372,7 @@ func TestScrambleSettles(t *testing.T) {
if same() {
t.Fatal("scramble started settled")
}
clk.add(200 * time.Millisecond)
clk.add(400 * time.Millisecond)
tt.Frame()
if !same() {
t.Fatal("after 6 steps the text had not settled")
+9 -3
View File
@@ -1,6 +1,7 @@
package text
import (
"fmt"
"log/slog"
"github.com/egoist/mygo/ui"
@@ -39,6 +40,11 @@ type typeState struct {
func Typewriter(c *ui.Context, s string, o TypewriterOptions) TypewriterResult {
k := pixel.K(c)
cps := pixel.Or("Typewriter CPS", o.CPS, 20)
if cps > 1000 {
panic(fmt.Sprintf("text: Typewriter CPS %d over 1000", cps))
}
// S5 steps at 4–15 fps; fast typing shows more.
fps := max(4, min(cps, 15))
shell, base, st := pixel.Shell(c, func() *ui.Element {
e := ui.Box(c).Role(ui.RoleText).Label(s).Disabled(o.Disabled)
if !o.Disabled {
@@ -61,11 +67,11 @@ func Typewriter(c *ui.Context, s string, o TypewriterOptions) TypewriterResult {
if !ts.done {
ts.last = total
if !k.Reduce() {
tick := k.Tick(c, cps)
tick := k.Tick(c, fps)
if ts.start < 0 {
ts.start = tick
}
ts.last = min(total, tick-ts.start)
ts.last = min(total, (tick-ts.start)*cps/fps)
}
if base.Clicked() {
ts.last = total
@@ -90,7 +96,7 @@ func Typewriter(c *ui.Context, s string, o TypewriterOptions) TypewriterResult {
left -= len(lr)
end = pixel.Measure(string(lr[:n]))
}
if shown == total && g.Step(2)%2 == 0 {
if shown == total && g.Step(4)%4 < 2 {
g.Sprite(end+3, len(lines)*pixel.LineHeight-6, more, 0, pixel.Accent, 1)
}
if st.Focus {