Files
8bitMyGoUI/desk/shutdownscreen.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

34 lines
1016 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package desk
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type ShutdownScreenOptions struct {
// Width and Height are dots; zeros mean 320 by 200.
Width, Height int
}
// ShutdownScreen says it is safe to turn off the computer.
func ShutdownScreen(c *ui.Context, o ShutdownScreenOptions) *ui.Element {
k := pixel.K(c)
w, h := pixel.Or("ShutdownScreen Width", o.Width, 320), pixel.Or("ShutdownScreen Height", o.Height, 200)
s := k.Msg("safe_to_turn_off")
lines := pixel.Wrap(s, (w-16)/2, 0)
if len(lines)*2*pixel.LineHeight > h-16 {
panic(fmt.Sprintf("desk: ShutdownScreen %d×%d is too small for its words", w, h))
}
return ui.Box(c).Size(k.D(w), k.D(h)).Role(ui.RoleText).Label(s).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
g.Rect(0, 0, w, h, pixel.Well)
top := (h - len(lines)*2*pixel.LineHeight) / 2
for i, l := range lines {
g.Text((w-2*pixel.Measure(l))/2, top+i*2*pixel.LineHeight, l, pixel.Warn, 2)
}
})
}