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>
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package media
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/input"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type TunerOptions struct {
|
|
Disabled bool
|
|
}
|
|
|
|
type TunerResult struct {
|
|
Element ui.Element
|
|
Changed bool
|
|
}
|
|
|
|
// Tuner sets *mhz on the FM dial by tenths.
|
|
func Tuner(c *ui.Context, text string, mhz *float64, o TunerOptions) TunerResult {
|
|
k := pixel.K(c)
|
|
const lo, hi = 87.5, 108.0
|
|
if !(*mhz >= lo && *mhz <= hi) {
|
|
panic(fmt.Sprintf("media: Tuner %v MHz outside FM", *mhz))
|
|
}
|
|
var res TunerResult
|
|
// The glass holds the scale; the scale is the slider.
|
|
res.Element = ui.Box(c).Size(k.D(176), k.D(32)).PaddingX(k.D(8)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Frame(0, 0, 176, 32, pixel.Sunken, pixel.Well)
|
|
g.Dither(2, 2, 172, 28, pixel.Well, pixel.Warn, 3)
|
|
g.HLine(8, 24, 162, pixel.Ink)
|
|
g.Micro(150, 26, "MHZ", pixel.Faint, 1)
|
|
}).Children(func() {
|
|
shell, st, changed := input.SlideBase(c, text, mhz, input.RailOptions{Min: lo, Max: hi, Step: 0.1, Disabled: o.Disabled})
|
|
res.Changed = changed
|
|
at := *mhz
|
|
shell.Size(k.D(160), k.D(32)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
// The dot under the pointer is the frequency it sets.
|
|
x := func(f float64) int { return int((f - lo) / (hi - lo) * 160) }
|
|
for f := 88; f <= 108; f++ {
|
|
h := 3
|
|
if f%4 == 0 {
|
|
h = 6
|
|
s := fmt.Sprint(f)
|
|
g.Micro(x(float64(f))-pixel.MicroWidth(s)/2, 4, s, pixel.Ink, 1)
|
|
}
|
|
g.VLine(x(float64(f)), 24-h, h, pixel.Ink)
|
|
}
|
|
g.Rect(x(at), 3, 2, 26, pixel.Bad)
|
|
g.Finish(st)
|
|
})
|
|
})
|
|
if res.Changed {
|
|
slog.Debug("8bit: tuner", "label", text, "mhz", *mhz)
|
|
}
|
|
return res
|
|
}
|