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.
This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 13:13:44 -04:00
1 parent d60d53ef90
commit 7800003418
39 files changed
+4120 -2

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
package desk_test
import (
"strings"
"testing"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/desk"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
func TestBadInputPanics(t *testing.T) {
big := pixel.MustSprite(strings.Repeat("#", 13))
bad := desk.Wallpaper(9)
n := 0
for name, build := range map[string]func(c *ui.Context){
"paper": func(c *ui.Context) { desk.Desktop(c, "D", desk.DesktopOptions{Wallpaper: bad}, func() {}) },
"picker": func(c *ui.Context) { desk.WallpaperPicker(c, "W", &bad, desk.WallpaperPickerOptions{}) },
"no label": func(c *ui.Context) { desk.DesktopIcon(c, "", icon.File, desk.DesktopIconOptions{}) },
"no icon": func(c *ui.Context) { desk.DesktopIcon(c, "A", nil, desk.DesktopIconOptions{}) },
"big icon": func(c *ui.Context) { desk.DesktopIcon(c, "A", big, desk.DesktopIconOptions{}) },
"no applets": func(c *ui.Context) { desk.ControlPanel(c, "P", nil, desk.ControlPanelOptions{}) },
"blank applet": func(c *ui.Context) {
desk.ControlPanel(c, "P", []desk.Applet{{Icon: icon.File}}, desk.ControlPanelOptions{})
},
"no programs": func(c *ui.Context) { desk.StartMenu(c, "S", nil, desk.StartMenuOptions{}) },
"slashed": func(c *ui.Context) {
desk.StartMenu(c, "S", []desk.Program{{Name: "A/B", Icon: icon.File}}, desk.StartMenuOptions{})
},
"twins": func(c *ui.Context) {
desk.StartMenu(c, "S", []desk.Program{{Name: "A", Icon: icon.File}, {Name: "A", Icon: icon.File}}, desk.StartMenuOptions{})
},
"empty submenu": func(c *ui.Context) {
desk.StartMenu(c, "S", []desk.Program{{Name: "A", Icon: icon.File, Programs: []desk.Program{}}}, desk.StartMenuOptions{})
},
"no tip": func(c *ui.Context) {
desk.TrayIcons(c, "T", []desk.TrayIcon{{Icon: icon.Wifi}}, desk.TrayIconsOptions{})
},
"active": func(c *ui.Context) {
a := 2
desk.Taskbar(c, "B", []string{"A", "B"}, &a, desk.TaskbarOptions{})
},
"no apps": func(c *ui.Context) { desk.Dock(c, "D", nil, desk.DockOptions{}) },
"nameless": func(c *ui.Context) { desk.Dock(c, "D", []desk.DockApp{{Icon: icon.Mail}}, desk.DockOptions{}) },
"mine field": func(c *ui.Context) { desk.Minesweeper(c, "M", desk.MinesweeperOptions{Cols: 2, Rows: 2, Mines: 4}) },
"tiny pit": func(c *ui.Context) { desk.Snake(c, "S", desk.SnakeOptions{Cols: 3, Rows: 3}) },
"small shut": func(c *ui.Context) { desk.ShutdownScreen(c, desk.ShutdownScreenOptions{Width: 60, Height: 20}) },
"no title": func(c *ui.Context) { desk.BootScreen(c, "", nil, desk.BootScreenOptions{}) },
"long post": func(c *ui.Context) { desk.BootScreen(c, "B", make([]string, 20), desk.BootScreenOptions{}) },
"blank clip": func(c *ui.Context) { desk.ClipboardPanel(c, "C", []string{""}, desk.ClipboardPanelOptions{}) },
"twin clips": func(c *ui.Context) { desk.ClipboardPanel(c, "C", []string{"a", "a"}, desk.ClipboardPanelOptions{}) },
"no logo": func(c *ui.Context) {
on := false
desk.Screensaver(c, "", &on, desk.ScreensaverOptions{})
},
} {
n++
mustPanic(t, name, func() { view(600, 300, newWorld(), build) })
}
if n != 23 {
t.Fatalf("%d cases", n)
}
}
func TestExtremesStayInside(t *testing.T) {
long := strings.Repeat("W", 60)
many := make([]string, 30)
for i := range many {
many[i] = long + string(rune('A'+i))
}
for _, tc := range []struct {
label string
build func(c *ui.Context)
}{
{long, func(c *ui.Context) { desk.DesktopIcon(c, long, icon.File, desk.DesktopIconOptions{Chosen: true}) }},
{"P", func(c *ui.Context) {
desk.ControlPanel(c, "P", []desk.Applet{{Name: long, Icon: icon.File}}, desk.ControlPanelOptions{})
}},
{"B", func(c *ui.Context) {
a := 3
desk.Taskbar(c, "B", many, &a, desk.TaskbarOptions{})
}},
{"C", func(c *ui.Context) { desk.ClipboardPanel(c, "C", []string{long + long}, desk.ClipboardPanelOptions{}) }},
{long, func(c *ui.Context) { desk.BootScreen(c, long, []string{long + long}, desk.BootScreenOptions{}) }},
} {
tt := view(1400, 700, newWorld(), tc.build)
tt.Frame()
x, y, w, h := dots(find(t, tt, tc.label))
if n := spill(tt.Image(), x, y, w, h); n > 0 {
t.Errorf("%.12s spills %d dots", tc.label, n)
}
}
}