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>
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package media
|
||
|
||
import (
|
||
"fmt"
|
||
"log/slog"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type GalleryOptions struct {
|
||
// Scale is the large picture's, 1–4; zero means 3.
|
||
Scale int
|
||
Disabled bool
|
||
}
|
||
|
||
type GalleryResult struct {
|
||
Element ui.Element
|
||
Changed bool
|
||
}
|
||
|
||
// Gallery shows the chosen picture large over its thumbnails.
|
||
func Gallery(c *ui.Context, text string, pics []*pixel.Sprite, names []string, chosen *int, o GalleryOptions) GalleryResult {
|
||
k := pixel.K(c)
|
||
sameSize("Gallery", pics)
|
||
if len(names) != len(pics) || *chosen < 0 || *chosen >= len(pics) {
|
||
panic(fmt.Sprintf("media: Gallery chose %d of %d pictures with %d names", *chosen, len(pics), len(names)))
|
||
}
|
||
s := scale("Gallery", o.Scale, 3)
|
||
pw, ph := pics[0].W, pics[0].H
|
||
res := GalleryResult{}
|
||
res.Element = ui.Column(c).Gap(k.D(4)).Children(func() {
|
||
big := pics[*chosen]
|
||
art(c, k, names[*chosen], pw*s+4, ph*s+4).Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
g.Frame(0, 0, g.W, g.H, pixel.Sunken, pixel.Well)
|
||
g.Sprite(2, 2, big, 0, pixel.Ink, s)
|
||
})
|
||
old := *chosen
|
||
// Arrows choose at once; the cursor is the choice.
|
||
shell, base, st, _ := pixel.Pad(c, text, len(pics), len(pics), pw+6, ph+6, chosen, o.Disabled)
|
||
base.Description(names[*chosen])
|
||
if res.Changed = *chosen != old; res.Changed {
|
||
slog.Debug("8bit: gallery", "label", text, "chosen", names[*chosen])
|
||
}
|
||
at := *chosen
|
||
shell.Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
for i, sp := range pics {
|
||
x := i * (pw + 6)
|
||
if i == at {
|
||
g.Cursor(x, 0, pw+6, ph+6)
|
||
}
|
||
g.Sprite(x+3, 3, sp, 0, pixel.Ink, 1)
|
||
}
|
||
g.Finish(st)
|
||
})
|
||
})
|
||
return res
|
||
}
|