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.
75 lines
2.2 KiB
Go
75 lines
2.2 KiB
Go
package account
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"time"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/datetime"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Session is a signed-in device and when it was seen.
|
|
type Session struct {
|
|
Device string
|
|
Icon *pixel.Sprite
|
|
Seen time.Time
|
|
Current bool
|
|
}
|
|
|
|
type SessionListOptions struct {
|
|
// Width is in dots; zero means 240.
|
|
Width int
|
|
Disabled bool
|
|
}
|
|
|
|
type SessionListResult struct {
|
|
Element *ui.Element
|
|
// SignedOut is the session signed out this frame, else -1.
|
|
SignedOut int
|
|
}
|
|
|
|
// 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).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)
|
|
})
|
|
}
|
|
ui.Column(c).Grow(1).Children(func() {
|
|
pixel.Text(c, s.Device, pixel.TextOptions{MaxLines: 1})
|
|
// This device is here now; others say when.
|
|
if s.Current {
|
|
pixel.Text(c, k.Msg("this_device"), pixel.TextOptions{Slot: pixel.Good})
|
|
} else {
|
|
datetime.RelativeTime(c, s.Seen, datetime.RelativeTimeOptions{})
|
|
}
|
|
})
|
|
if input.Button(c, k.Msg("sign_out"), input.ButtonOptions{Size: input.Small, Variant: input.Danger, Disabled: o.Disabled, Label: k.Msg("sign_out") + " " + s.Device}).Clicked {
|
|
res.SignedOut = i
|
|
}
|
|
})
|
|
}
|
|
})
|
|
if res.SignedOut >= 0 {
|
|
slog.Debug("8bit: session list sign out", "label", text, "session", res.SignedOut)
|
|
}
|
|
return res
|
|
}
|