Files
8bitMyGoUI/media/gallery.go
T
ZacharyZhang-NY 0e21870b64 Add media components 346-365; input.SlideBase, guarded Pad
An audio player with transport, scrubber and volume; an equalizer and
a visualizer; a playlist; a cassette, cartridge and record that turn
while they play and hold where they stop; piano keys, a step sequencer
and a tracker you can type into; a waveform, a 16:9 video frame, an
image compare, a gallery, a filmstrip, a record button and an FM tuner.

input exports SlideBase, the undrawn rail its sliders share; the
gallery treats exported Bases as building blocks, not components.
pixel's micro font gains '#' for notes like C#4. pixel.Pad and the
slide rail read input only while their base is enabled, so Inert or a
fresh Disabled stops a drag or a key already sent. AGENTS records why
a drawn container keeps the DISABLED description: MyGo paints a
disabled subtree at half opacity.
2026-10-12 06:17:12 -04:00

62 lines
1.7 KiB
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 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
}