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.
128 lines
2.8 KiB
Go
128 lines
2.8 KiB
Go
package gallery
|
|
|
|
import (
|
|
"log/slog"
|
|
"strings"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Dot is the gallery's DIPs per dot.
|
|
const Dot = 2
|
|
|
|
// App is the gallery that native and web share.
|
|
type App struct {
|
|
router *ui.Router
|
|
palette int
|
|
locale pixel.Locale
|
|
started bool
|
|
query string
|
|
search input.TextInputResult
|
|
logs map[string][]string
|
|
}
|
|
|
|
// New starts at path; the boot screen shows first.
|
|
func New(path string) *App {
|
|
r := ui.NewRouter(path)
|
|
r.Transition = ui.TransitionNone
|
|
return &App{router: r, logs: map[string][]string{}}
|
|
}
|
|
|
|
// Path is the page shown, for the web address bar.
|
|
func (a *App) Path() string { return a.router.Location() }
|
|
|
|
// Go opens path, skipping boot and clearing search.
|
|
func (a *App) Go(path string) {
|
|
a.started, a.query = true, ""
|
|
if path != a.router.Location() {
|
|
slog.Debug("8bit: gallery go", "path", path)
|
|
a.router.Push(path)
|
|
}
|
|
}
|
|
|
|
func (a *App) View(c *ui.Context) {
|
|
pixel.Use(c, pixel.Settings{Palette: pixel.Palettes[a.palette], Dot: Dot, Locale: a.locale})
|
|
if !a.started {
|
|
a.boot(c)
|
|
return
|
|
}
|
|
ui.Column(c).Fill().Children(func() {
|
|
a.topBar(c)
|
|
ui.Row(c).Grow(1).AlignItems(ui.Stretch).Children(func() {
|
|
a.sidebar(c)
|
|
ui.Column(c).Grow(1).Children(func() { a.content(c) })
|
|
})
|
|
a.statusBar(c)
|
|
})
|
|
a.keys(c)
|
|
}
|
|
|
|
// keys leaves single keys to a field being typed in.
|
|
func (a *App) keys(c *ui.Context) {
|
|
if pixel.Typing(c) {
|
|
return
|
|
}
|
|
switch {
|
|
case c.Shortcut(0, ui.KeySlash):
|
|
a.search.Input.Focus()
|
|
case c.Shortcut(0, ui.KeyP):
|
|
a.setPalette(a.palette + 1)
|
|
case c.Shortcut(ui.Shift, ui.KeyP):
|
|
a.setPalette(a.palette - 1)
|
|
case c.Shortcut(0, ui.KeyBracketLeft):
|
|
a.step(-1)
|
|
case c.Shortcut(0, ui.KeyBracketRight):
|
|
a.step(1)
|
|
}
|
|
}
|
|
|
|
func (a *App) setPalette(i int) {
|
|
n := len(pixel.Palettes)
|
|
a.palette = (i%n + n) % n
|
|
slog.Debug("8bit: gallery palette", "name", pixel.Palettes[a.palette].Name)
|
|
}
|
|
|
|
// step moves to the previous or next entry.
|
|
func (a *App) step(d int) {
|
|
all := Entries()
|
|
for i, e := range all {
|
|
if e.Path() == a.router.Path() {
|
|
a.Go(all[((i+d)%len(all)+len(all))%len(all)].Path())
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
// logger records a demo's events for the log panel.
|
|
func (a *App) logger(e Entry) func(string) {
|
|
return func(ev string) {
|
|
// The panel shows what was typed; logs never do.
|
|
slog.Debug("8bit: demo", "entry", e.Slug())
|
|
l := append(a.logs[e.Slug()], ev)
|
|
a.logs[e.Slug()] = l[max(0, len(l)-8):]
|
|
}
|
|
}
|
|
|
|
func find(slug string) (Entry, bool) {
|
|
for _, e := range Entries() {
|
|
if e.Slug() == slug {
|
|
return e, true
|
|
}
|
|
}
|
|
return Entry{}, false
|
|
}
|
|
|
|
func matches(q string) []Entry {
|
|
q = strings.ToLower(strings.TrimSpace(q))
|
|
var out []Entry
|
|
for _, e := range Entries() {
|
|
if strings.Contains(strings.ToLower(e.Name+" "+e.Zh+" "+e.Slug()), q) {
|
|
out = append(out, e)
|
|
}
|
|
}
|
|
return out
|
|
}
|