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>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package media
|
||
|
||
import (
|
||
"fmt"
|
||
"math"
|
||
"strings"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type VisualizerOptions struct {
|
||
// Height is in dots; zero means 32.
|
||
Height int
|
||
}
|
||
|
||
// Visualizer mirrors each level, 0 to 1, about the middle.
|
||
func Visualizer(c *ui.Context, text string, levels []float64, o VisualizerOptions) ui.Element {
|
||
k := pixel.K(c)
|
||
if len(levels) == 0 {
|
||
panic("media: Visualizer has no levels")
|
||
}
|
||
parts := make([]string, len(levels))
|
||
for i, l := range levels {
|
||
if !(l >= 0 && l <= 1) {
|
||
panic(fmt.Sprintf("media: Visualizer level %v outside 0–1", l))
|
||
}
|
||
parts[i] = fmt.Sprintf("%.2f", l)
|
||
}
|
||
h := pixel.Or("Visualizer Height", o.Height, 32)
|
||
mid := h / 2
|
||
return art(c, k, text, 4*len(levels)-1, h).Description(strings.Join(parts, " ")).Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
for i, l := range levels {
|
||
n := int(math.Round(l * float64(mid)))
|
||
if n == 0 {
|
||
continue
|
||
}
|
||
// Magic at the root, Accent above, an AccentLit tip.
|
||
x, deep := 4*i, n/2
|
||
g.Rect(x, mid-deep, 3, 2*deep, pixel.Magic)
|
||
g.Rect(x, mid-n+1, 3, n-1-deep, pixel.Accent)
|
||
g.Rect(x, mid+deep, 3, n-1-deep, pixel.Accent)
|
||
g.Rect(x, mid-n, 3, 1, pixel.AccentLit)
|
||
g.Rect(x, mid+n-1, 3, 1, pixel.AccentLit)
|
||
}
|
||
})
|
||
}
|