Files
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

68 lines
1.7 KiB
Go

package media
import (
"fmt"
"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 VolumeOptions struct {
// Bars is how many steps; zero means 8.
Bars int
Disabled bool
}
type VolumeResult struct {
Element ui.Element
Changed bool
}
// Volume sets *level in stepped bars; the speaker mutes.
func Volume(c *ui.Context, text string, level *int, muted *bool, o VolumeOptions) VolumeResult {
k := pixel.K(c)
n := pixel.Or("Volume Bars", o.Bars, 8)
if n < 2 || *level < 0 || *level > n {
panic(fmt.Sprintf("media: Volume level %d of %d bars", *level, n))
}
var res VolumeResult
res.Element = ui.Row(c).Gap(k.D(3)).AlignItems(ui.Center).Children(func() {
sp := icon.Volume
if *muted {
sp = icon.Mute
}
mute := input.Toggle(c, "", muted, input.ToggleOptions{Icon: sp, Label: k.Msg("mute"), Disabled: o.Disabled}).Changed
v := float64(*level)
shell, st, moved := input.SlideBase(c, text, &v, input.RailOptions{Max: float64(n), Step: 1, Disabled: o.Disabled})
*level = int(v)
lit, quiet := *level, *muted
shell.Size(k.D(4*n), k.D(14)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
for i := range n {
h := 4 + i*10/(n-1)
s := pixel.Well
switch {
case i >= lit:
case quiet:
s = pixel.Faint
case i >= n*3/4:
s = pixel.Warn
default:
s = pixel.Good
}
g.Frame(4*i, 14-h, 3, h, pixel.Flat, s)
}
g.Finish(st)
})
res.Changed = mute || moved
})
if res.Changed {
slog.Debug("8bit: volume", "label", text, "level", *level, "muted", *muted)
}
return res
}