Files
8bitMyGoUI/desk/lockscreen.go
T
ZacharyZhang-NY 7800003418 Add desk components 466-485 and icon.Bomb
Twenty pieces of a retro desktop: Desktop, DesktopIcon, Taskbar,
StartMenu, AppWindow, Calculator, Notepad, Minesweeper, ControlPanel,
TrayIcons, ShutdownScreen, BootScreen, Screensaver, Snake, Dock,
RunDialog, DiskDefrag, WallpaperPicker, ClipboardPanel and LockScreen.

The calculator really adds up and calls division by zero GAME OVER;
Minesweeper and Snake are playable, first click always safe; START
cascades its submenus without moving the rows already open; windows
drag by whole dots; the screensaver's logo changes color at each wall
and sparkles in a corner; the defragmenter is oddly soothing. Clocks
that step back hold at zero, and typed or copied text never reaches
the log.

icon.Bomb is the new 12x12 mine.
2026-10-12 13:13:44 -04:00

51 lines
1.5 KiB
Go

package desk
import (
"fmt"
"log/slog"
"strings"
"time"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type LockScreenOptions struct{}
type LockScreenResult struct {
Element *ui.Element
// Unlocked is a key or click opening it this frame.
Unlocked bool
}
// LockScreen covers the window: time, date, PRESS ANY KEY.
func LockScreen(c *ui.Context, text string, open *bool, o LockScreenOptions) LockScreenResult {
k := pixel.K(c)
now := k.Now()
if *open {
k.At(c, now.Truncate(time.Minute).Add(time.Minute))
}
clock := now.Format("15:04")
days, months := strings.Fields(k.Msg("days")), strings.Fields(k.Msg("months"))
date := fmt.Sprintf(k.Msg("day_date"), days[now.Weekday()], now.Day(), months[now.Month()-1], int(now.Month()))
press := k.Msg("press_any_key")
anchor, panel, woke := cover(c, k, text, open, false, func(g pixel.Canvas) {
g.Rect(0, 0, g.W, g.H, pixel.Well)
cy := g.H/2 - 40
g.Text((g.W-4*pixel.Measure(clock))/2, cy, clock, pixel.Ink, 4)
g.Text((g.W-pixel.Measure(date))/2, cy+4*pixel.LineHeight+4, date, pixel.Faint, 1)
// The prompt blinks on 4 fps steps; reduced, it holds.
if g.Step(4)%4 < 2 {
g.Text((g.W-pixel.Measure(press))/2, g.H-3*pixel.LineHeight, press, pixel.Accent, 1)
}
})
if panel != nil {
panel.Description(clock + ", " + date + ", " + press)
}
if woke {
slog.Debug("8bit: lock screen unlocked", "label", text)
}
return LockScreenResult{Element: anchor, Unlocked: woke}
}