Files
8bitMyGoUI/desk/wallpaperpicker.go
T
ZacharyZhang-NYandClaude Opus 5.5 03e1f91706 Upgrade MyGo to v0.5.5
Elements are now pass-scoped value handles: tests that read bounds
after a frame bind a ui.Handle. pixel tells frames apart by the build
pass's root, since the Tester clock no longer moves on its own.

Fix the regressions the upgrade brought:
- Clipboard reads in input handlers go through c.Services().
- MyGo notes an overlay's opener after building it, so AutoFocus
  inside lost it; pixel.AutoFocus focuses through a Handle, and
  archtest bans the raw call. Dialogs hand the focus back again.
- Elements around a press stay hovered: Tooltip tells a press-given
  focus by focus arriving under the pointer.
- The web host moves the Tester clock with real time, at most 500 ms
  a call, and gives components the real clock.

The gallery's source index also accepts CRLF checkouts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-17 01:31:08 -04:00

65 lines
1.6 KiB
Go

package desk
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type WallpaperPickerOptions struct {
Disabled bool
}
type WallpaperPickerResult struct {
Element ui.Element
Changed bool
}
type pickerKey struct{}
const swatchW, swatchH = 44, 36
// WallpaperPicker chooses a dither pattern by its swatch.
func WallpaperPicker(c *ui.Context, text string, chosen *Wallpaper, o WallpaperPickerOptions) WallpaperPickerResult {
k := pixel.K(c)
chosen.name(k)
col := ui.Column(c).Gap(k.D(4))
cur := ui.Local(col, pickerKey{}, func() int { return int(*chosen) })
res := WallpaperPickerResult{}
res.Element = col.Children(func() {
shell, base, st, picked := pixel.Pad(c, text, 3, len(papers), swatchW, swatchH, cur, o.Disabled)
if picked >= 0 && Wallpaper(picked) != *chosen {
*chosen, res.Changed = Wallpaper(picked), true
}
at, pick := *cur, *chosen
said := Wallpaper(at).name(k)
if Wallpaper(at) == pick {
said += ", " + k.Msg("chosen")
}
base.Description(said)
shell.Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
for i := range papers {
x, y := i%3*swatchW, i/3*swatchH
if i == at && st.Focus {
g.Cursor(x, y, swatchW, swatchH)
}
ring := pixel.Edge
if Wallpaper(i) == pick {
ring = pixel.Accent
}
g.Rect(x+2, y+2, swatchW-4, swatchH-4, ring)
paper(g, x+4, y+4, swatchW-8, swatchH-8, Wallpaper(i))
}
g.Finish(st)
})
pixel.Text(c, Wallpaper(at).name(k), pixel.TextOptions{Slot: pixel.Faint})
})
if res.Changed {
slog.Debug("8bit: wallpaper chosen", "label", text, "wallpaper", int(*chosen))
}
return res
}