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:
198 files changed
+2708
-422
No files matched your search
+3
-4
@@ -13,19 +13,18 @@ type Credit struct {
|
||||
}
|
||||
|
||||
type AboutOptions struct {
|
||||
Version string
|
||||
Credits []Credit
|
||||
}
|
||||
|
||||
// About shows the title as a logo, version, then credits.
|
||||
func About(c *ui.Context, title string, o AboutOptions) *ui.Element {
|
||||
func About(c *ui.Context, title, version string, o AboutOptions) *ui.Element {
|
||||
k := pixel.K(c)
|
||||
if o.Version == "" {
|
||||
if version == "" {
|
||||
panic("account: About needs a version")
|
||||
}
|
||||
return ui.Column(c).Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleGroup).Label(title).Children(func() {
|
||||
text.OutlineText(c, title, text.OutlineTextOptions{Slot: pixel.Accent, Scale: 3})
|
||||
pixel.Text(c, k.Msg("version")+" "+o.Version, pixel.TextOptions{Slot: pixel.Faint})
|
||||
pixel.Text(c, k.Msg("version")+" "+version, pixel.TextOptions{Slot: pixel.Faint})
|
||||
if len(o.Credits) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -75,23 +75,23 @@ func KeyBindings(c *ui.Context, text string, binds []Binding, o KeyBindingsOptio
|
||||
kb.waiting = false
|
||||
case kb.waiting:
|
||||
// Waiting, every key binds, arrows too; Escape gives up.
|
||||
if base.Shortcut(0, ui.KeyEscape) {
|
||||
if pixel.Shortcut(base, 0, ui.KeyEscape) {
|
||||
kb.waiting = false
|
||||
}
|
||||
for key := range caps {
|
||||
if base.Shortcut(0, key) && kb.waiting {
|
||||
if pixel.Shortcut(base, 0, key) && kb.waiting {
|
||||
binds[kb.cur].Key, kb.waiting, res.Changed = key, false, true
|
||||
slog.Debug("8bit: key bindings", "label", text, "action", binds[kb.cur].Action, "key", caps[key])
|
||||
}
|
||||
}
|
||||
default:
|
||||
if base.Shortcut(0, ui.KeyUp) {
|
||||
if pixel.Shortcut(base, 0, ui.KeyUp) {
|
||||
kb.cur = max(0, kb.cur-1)
|
||||
}
|
||||
if base.Shortcut(0, ui.KeyDown) {
|
||||
if pixel.Shortcut(base, 0, ui.KeyDown) {
|
||||
kb.cur = min(len(binds)-1, kb.cur+1)
|
||||
}
|
||||
if base.Shortcut(0, ui.KeyEnter) || base.Shortcut(0, ui.KeySpace) {
|
||||
if pixel.Shortcut(base, 0, ui.KeyEnter) || pixel.Shortcut(base, 0, ui.KeySpace) {
|
||||
kb.waiting = true
|
||||
}
|
||||
if base.Clicked() {
|
||||
|
||||
@@ -34,11 +34,11 @@ func OptionCycler(c *ui.Context, text string, options []string, selected *int, o
|
||||
n, old := len(options), *selected
|
||||
if !base.IsDisabled() {
|
||||
step := 0
|
||||
if base.Shortcut(0, ui.KeyLeft) {
|
||||
if pixel.Shortcut(base, 0, ui.KeyLeft) {
|
||||
step--
|
||||
}
|
||||
// Enter and Space step on; taken, clicks come from pointers.
|
||||
right, enter, space := base.Shortcut(0, ui.KeyRight), base.Shortcut(0, ui.KeyEnter), base.Shortcut(0, ui.KeySpace)
|
||||
right, enter, space := pixel.Shortcut(base, 0, ui.KeyRight), pixel.Shortcut(base, 0, ui.KeyEnter), pixel.Shortcut(base, 0, ui.KeySpace)
|
||||
if right || enter || space {
|
||||
step++
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func PasswordGrid(c *ui.Context, text string, password *string, o PasswordGridOp
|
||||
if picked >= 0 && len(*password) < n {
|
||||
*password += symbols[picked : picked+1]
|
||||
}
|
||||
if !base.IsDisabled() && base.Shortcut(0, ui.KeyBackspace) && *password != "" {
|
||||
if !base.IsDisabled() && pixel.Shortcut(base, 0, ui.KeyBackspace) && *password != "" {
|
||||
*password = (*password)[:len(*password)-1]
|
||||
}
|
||||
base.Description(symbols[*cur : *cur+1])
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestPlayerSelectChooses(t *testing.T) {
|
||||
func TestAboutAndPatchNotesRead(t *testing.T) {
|
||||
tt := view(500, 400, newWorld(), func(c *ui.Context) {
|
||||
ui.Row(c).Children(func() {
|
||||
account.About(c, "GAME", account.AboutOptions{Version: "1.2", Credits: []account.Credit{{Role: "Art", Name: "Ann"}}})
|
||||
account.About(c, "GAME", "1.2", account.AboutOptions{Credits: []account.Credit{{Role: "Art", Name: "Ann"}}})
|
||||
account.PatchNotes(c, "Notes", []account.Patch{{Version: "v2", Added: []string{"Boats"}, Fixed: []string{"Rain"}}}, account.PatchNotesOptions{Width: 120})
|
||||
})
|
||||
})
|
||||
@@ -157,6 +157,6 @@ func TestAboutAndPatchNotesRead(t *testing.T) {
|
||||
t.Fatal("the ADDED tag is not Good")
|
||||
}
|
||||
mustPanic(t, "no version", func() {
|
||||
view(500, 400, newWorld(), func(c *ui.Context) { account.About(c, "G", account.AboutOptions{}) })
|
||||
view(500, 400, newWorld(), func(c *ui.Context) { account.About(c, "G", "", account.AboutOptions{}) })
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package account_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/egoist/mygo/ui"
|
||||
|
||||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/account"
|
||||
)
|
||||
|
||||
func TestSessionFocusFollowsItsRow(t *testing.T) {
|
||||
wd := newWorld()
|
||||
ss := []account.Session{{Device: "Laptop", Seen: wd.clk.t}, {Device: "Phone", Seen: wd.clk.t}, {Device: "Tablet", Seen: wd.clk.t}}
|
||||
gone := ""
|
||||
tt := view(600, 400, wd, func(c *ui.Context) {
|
||||
if r := account.SessionList(c, "Sessions", ss, account.SessionListOptions{}); r.SignedOut >= 0 {
|
||||
gone = ss[r.SignedOut].Device
|
||||
}
|
||||
})
|
||||
tt.Key(0, ui.KeyTab)
|
||||
tt.Key(0, ui.KeyTab)
|
||||
// The laptop leaves; the focus stays on the phone's button.
|
||||
ss = ss[1:]
|
||||
tt.Frame()
|
||||
tt.Key(0, ui.KeyEnter)
|
||||
if gone != "Phone" {
|
||||
t.Fatalf("Enter after the laptop left signed out %q", gone)
|
||||
}
|
||||
defer func() {
|
||||
if r := fmt.Sprint(recover()); !strings.HasPrefix(r, "account: SessionList") {
|
||||
t.Fatalf("two phones gave %q", r)
|
||||
}
|
||||
}()
|
||||
twins := []account.Session{{Device: "Phone"}, {Device: "Phone"}}
|
||||
view(600, 400, newWorld(), func(c *ui.Context) { account.SessionList(c, "S", twins, account.SessionListOptions{}) })
|
||||
}
|
||||
+10
-1
@@ -1,6 +1,7 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
@@ -34,10 +35,18 @@ type SessionListResult struct {
|
||||
// SessionList lists signed-in devices, each with SIGN OUT.
|
||||
func SessionList(c *ui.Context, text string, sessions []Session, o SessionListOptions) SessionListResult {
|
||||
k := pixel.K(c)
|
||||
// Rows are keyed by device, so focus follows its row.
|
||||
seen := map[string]bool{}
|
||||
for _, s := range sessions {
|
||||
if seen[s.Device] {
|
||||
panic(fmt.Sprintf("account: SessionList has %q twice", s.Device))
|
||||
}
|
||||
seen[s.Device] = true
|
||||
}
|
||||
res := SessionListResult{SignedOut: -1}
|
||||
res.Element = ui.Column(c).Width(k.D(pixel.Or("SessionList Width", o.Width, 240))).Gap(k.D(4)).Role(ui.RoleList).Label(text).Children(func() {
|
||||
for i, s := range sessions {
|
||||
ui.Row(c).FillWidth().Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleListItem).Children(func() {
|
||||
ui.Row(c).Key(s.Device).FillWidth().Gap(k.D(4)).AlignItems(ui.Center).Role(ui.RoleListItem).Children(func() {
|
||||
if s.Icon != nil {
|
||||
ui.Box(c).Size(k.D(s.Icon.W), k.D(s.Icon.H)).Draw(func(p *ui.Painter, r ui.Rect) {
|
||||
k.Canvas(p, r).Sprite(0, 0, s.Icon, 0, pixel.Ink, 1)
|
||||
|
||||
Reference in new issue
Block a user