Files
8bitMyGoUI/media/transport.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

48 lines
1.5 KiB
Go

package media
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/icon"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type TransportOptions struct {
Disabled bool
}
type TransportResult struct {
Element *ui.Element
// Changed is play or pause; the rest are presses.
Changed, Stopped, Previous, Next bool
}
// Transport is ⏮ ▶/❚❚ ■ ⏭; play toggles *playing.
func Transport(c *ui.Context, text string, playing *bool, o TransportOptions) TransportResult {
k := pixel.K(c)
var res TransportResult
res.Element = ui.Row(c).Gap(k.D(2)).FocusGroup(ui.Horizontal).Role(ui.RoleToolbar).Label(text).Children(func() {
press := func(sp *pixel.Sprite, key string) bool {
return input.IconButton(c, sp, k.Msg(key), input.IconButtonOptions{Disabled: o.Disabled}).Clicked
}
res.Previous = press(prev, "prev_track")
sp := icon.Play
if *playing {
sp = icon.Pause
}
res.Changed = input.Toggle(c, "", playing, input.ToggleOptions{Icon: sp, Label: k.Msg("play"), Disabled: o.Disabled}).Changed
// Stop ends play too.
if res.Stopped = press(icon.Stop, "stop"); res.Stopped && *playing {
*playing, res.Changed = false, true
}
res.Next = press(icon.Next, "next_track")
})
if res.Changed || res.Stopped || res.Previous || res.Next {
slog.Debug("8bit: transport", "label", text, "playing", *playing, "stopped", res.Stopped, "previous", res.Previous, "next", res.Next)
}
return res
}