Add account components 386-405; Reduce setting, PinInput Cmd+V
Twenty account components: SettingsList, OptionCycler, KeyBindings, ControllerMap, ProfileCard, CharacterCreator, LoginForm, PasswordGrid, SessionList, LanguagePicker, PalettePicker, VolumeMixer, DifficultySelect, AccessibilityOptions, AccountSwitcher, PlayerSelect, TwoFactor, About, PatchNotes and FeedbackForm. The components never check credentials, and no secret reaches the log: LoginForm reports Submitted and the caller counts Failures; each new failure clears the password, refocuses it, shakes the form and names no field. TwoFactor builds on input.PinInput and drains an epoch-aligned period bar. PalettePicker draws each tile in its own palette on a pixel.Pad grid. pixel.Settings.Reduce stills motion like the system preference, the micro font gains '?', display.Face draws avatar faces anywhere, and input.PinInput pastes on Cmd+V as native hosts send it.
This commit is contained in:
38 files changed
+2788
-13
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package account
|
||||
|
||||
import (
|
||||
"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)
|
||||
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() {
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user