Upgrade MyGo to v0.5.5
MyGo v0.5.5 returns ui.Element as a checked value handle instead of a
pointer. Migrated with `mygo migrate-ui`, then fixed what the codemod
leaves to review:
- Element nil checks become .Valid(); absent elements are ui.Element{}.
- Input handlers and paint callbacks run outside the build pass, where
elements expire and Context methods are inert: read IsDisabled into a
local during the build, keep a ui.Handle for Focus, use c.Services()
for clipboard access, create ui.Local state during the build.
- Add core.AutoFocus: v0.5.5 records an overlay's opener after its
content builds, so same-frame autofocus lost focus restore on close.
It focuses one frame later; cascader rows defer their focus likewise.
- core.OverlayLayer identifies build passes by the root element, not
c.Now(), which repeats across passes and under the Tester clock.
- Context menus survive the opening press counted as PressedOutside;
split button tooltip no longer reorders its open menu; disabled
menubar rows pass presses to the panel; Form defers blur-started
async checks so the growing message no longer moves Submit away
from the release; Combobox drops its disabled copy now that MyGo
blocks typing under a disabled wrapper (canary flipped to a guard).
- The Tester clock is virtual: tests use Advance/Now instead of
time.Sleep/time.Now and read element state inside the view. The web
mirror advances the clock to wall time before each frame and input.
- AGENTS.md and docs describe the value Element API and the new pin.
Snapshot goldens are darwin-only and were not re-verified here.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
bc716d27be
commit
bcce34cda1
603 files changed
+1366
-1277
No files matched your search
@@ -27,7 +27,7 @@ type AudioPlayerOptions struct {
|
||||
}
|
||||
|
||||
// AudioPlayer is a play, pause and seek shell.
|
||||
func AudioPlayer(c *ui.Context, st AudioState, opts AudioPlayerOptions) *ui.Element {
|
||||
func AudioPlayer(c *ui.Context, st AudioState, opts AudioPlayerOptions) ui.Element {
|
||||
if opts.OnPlay == nil || opts.OnPause == nil || opts.OnSeek == nil {
|
||||
panic("mujica: AudioPlayer needs OnPlay, OnPause and OnSeek")
|
||||
}
|
||||
@@ -63,7 +63,7 @@ func AudioPlayer(c *ui.Context, st AudioState, opts AudioPlayerOptions) *ui.Elem
|
||||
}
|
||||
|
||||
// mediaPlayToggle is the play/pause button; it calls the matching callback.
|
||||
func mediaPlayToggle(c *ui.Context, playing bool, onPlay, onPause func()) *ui.Element {
|
||||
func mediaPlayToggle(c *ui.Context, playing bool, onPlay, onPause func()) ui.Element {
|
||||
icon, label := core.MediaPlay, core.Msg(c, "media_controls.play")
|
||||
if playing {
|
||||
icon, label = core.MediaPause, core.Msg(c, "media_controls.pause")
|
||||
|
||||
@@ -29,7 +29,7 @@ type AudioSpectrumOptions struct {
|
||||
type spectrumKey struct{}
|
||||
|
||||
// AudioSpectrum draws caller bands as bars; it never animates itself.
|
||||
func AudioSpectrum(c *ui.Context, bands []float32, opts AudioSpectrumOptions) *ui.Element {
|
||||
func AudioSpectrum(c *ui.Context, bands []float32, opts AudioSpectrumOptions) ui.Element {
|
||||
for _, b := range bands {
|
||||
if b < 0 || b > 1 || math.IsNaN(float64(b)) {
|
||||
panic("mujica: AudioSpectrum band outside 0..1")
|
||||
@@ -99,7 +99,7 @@ func spectrumReadout(name string, v float32) string {
|
||||
}
|
||||
|
||||
// chartCursor moves *cur by arrows, Home and End.
|
||||
func chartCursor(e *ui.Element, cur *int, n int) (moved, ok bool) {
|
||||
func chartCursor(e ui.Element, cur *int, n int) (moved, ok bool) {
|
||||
if e.IsDisabled() || n == 0 {
|
||||
return false, false
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func chartCursor(e *ui.Element, cur *int, n int) (moved, ok bool) {
|
||||
}
|
||||
|
||||
// mediaChartState fills e with a loading, error or empty state.
|
||||
func mediaChartState(c *ui.Context, e *ui.Element, status data.DataStatus, errText string, empty bool, emptyKey string) bool {
|
||||
func mediaChartState(c *ui.Context, e ui.Element, status data.DataStatus, errText string, empty bool, emptyKey string) bool {
|
||||
k := core.Tokens(c)
|
||||
switch {
|
||||
case status == data.DataLoading:
|
||||
|
||||
@@ -127,7 +127,7 @@ func waveformBucket(samples []float32, cols int) []float32 {
|
||||
}
|
||||
|
||||
// waveformInput seeks and selects; true means the selection changed.
|
||||
func waveformInput(c *ui.Context, e *ui.Element, r ui.Rect, opts AudioWaveformOptions) bool {
|
||||
func waveformInput(c *ui.Context, e ui.Element, r ui.Rect, opts AudioWaveformOptions) bool {
|
||||
at := func(x float32) time.Duration {
|
||||
f := max(0, min(1, (x-r.X)/max(1, r.W)))
|
||||
return time.Duration(float64(f) * float64(opts.Duration)).Round(time.Millisecond)
|
||||
|
||||
@@ -185,7 +185,7 @@ func annotatorPreview(s *annotatorState) []Annotation {
|
||||
}
|
||||
|
||||
// annotatorPointer draws shapes, selects by click, drags the selection.
|
||||
func annotatorPointer(stage *ui.Element, s *annotatorState, notes *[]Annotation, r ui.Rect, size image.Point, scale, ox, oy float32) {
|
||||
func annotatorPointer(stage ui.Element, s *annotatorState, notes *[]Annotation, r ui.Rect, size image.Point, scale, ox, oy float32) {
|
||||
_, _, _ = stage.Dragged()
|
||||
px, py, _ := stage.PointerPosition()
|
||||
pt := image.Pt(int(math.Round(float64((px+r.X-ox)/scale))), int(math.Round(float64((py+r.Y-oy)/scale))))
|
||||
@@ -218,7 +218,7 @@ func annotatorPointer(stage *ui.Element, s *annotatorState, notes *[]Annotation,
|
||||
}
|
||||
|
||||
// annotatorKeys: [ ] select, arrows move, Delete removes, Escape clears.
|
||||
func annotatorKeys(stage *ui.Element, s *annotatorState, notes *[]Annotation, size image.Point) {
|
||||
func annotatorKeys(stage ui.Element, s *annotatorState, notes *[]Annotation, size image.Point) {
|
||||
n := len(*notes)
|
||||
step := max(1, size.X/100)
|
||||
move := func(dx, dy int) {
|
||||
|
||||
@@ -37,7 +37,7 @@ func ImageCompare(c *ui.Context, before, after ui.ImageSource, split *float64, o
|
||||
}
|
||||
g, _ := input.SliderSetup(0, 1, 0.01, nil, false, c)
|
||||
old := *split
|
||||
var s *ui.Element
|
||||
var s ui.Element
|
||||
var next float64
|
||||
ui.Box(c).Disabled(opts.Disabled).Children(func() {
|
||||
s, next, _ = input.SliderControl(c, old, g, 0, 1)
|
||||
|
||||
@@ -210,7 +210,7 @@ func cropperRotate(cr *ImageCrop, size image.Point, d int, aspect float64) {
|
||||
}
|
||||
|
||||
// cropperPointer moves the frame, or resizes it by a corner.
|
||||
func cropperPointer(stage *ui.Element, cr *ImageCrop, r ui.Rect, size image.Point, scale, ox, oy float32, aspect float64) {
|
||||
func cropperPointer(stage ui.Element, cr *ImageCrop, r ui.Rect, size image.Point, scale, ox, oy float32, aspect float64) {
|
||||
d := ui.Local(stage, cropperDrag{}, func() cropperDrag { return cropperDrag{} })
|
||||
dx, dy, ok := stage.Dragged()
|
||||
if !stage.Pressed() {
|
||||
|
||||
@@ -48,7 +48,7 @@ func cropperClampSize(w, h int, room image.Point, aspect float64) (int, int) {
|
||||
}
|
||||
|
||||
// cropperKeys: arrows move, Shift+arrows resize, 1% per press.
|
||||
func cropperKeys(stage *ui.Element, cr *ImageCrop, size image.Point, aspect float64) {
|
||||
func cropperKeys(stage ui.Element, cr *ImageCrop, size image.Point, aspect float64) {
|
||||
step := max(1, size.X/100)
|
||||
r := cr.Rect
|
||||
move := func(dx, dy int) { cr.Rect = cropperDragRect(r, 1, dx, dy, size, aspect) }
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ func Lightbox(c *ui.Context, open *bool, index *int, images []data.ViewerImage)
|
||||
u := core.Density(c).Unit()
|
||||
w, h := c.Size()
|
||||
light := ui.Hex("#F2EBDD")
|
||||
v.Element = ui.DialogBase(c, open, func(back, panel *ui.Element) {
|
||||
v.Element = ui.DialogBase(c, open, func(back, panel ui.Element) {
|
||||
back.Background(ui.RGBA(0, 0, 0, 0.92))
|
||||
panel.Size(w, h).Padding(u * 4).Gap(u * 3).TextColor(light).Label(core.Msg(c, "lightbox.title")).
|
||||
Opacity(core.OverlayEnter(c, panel))
|
||||
@@ -79,7 +79,7 @@ func Lightbox(c *ui.Context, open *bool, index *int, images []data.ViewerImage)
|
||||
}
|
||||
|
||||
// lightboxButton is a 40 DIP icon button on the backdrop.
|
||||
func lightboxButton(c *ui.Context, icon, key string, disabled bool) *ui.Element {
|
||||
func lightboxButton(c *ui.Context, icon, key string, disabled bool) ui.Element {
|
||||
light := ui.Hex("#F2EBDD")
|
||||
b := core.IconAction(c, icons.Must(icon), core.Msg(c, key)).Size(40, 40).TextColor(light).Disabled(disabled)
|
||||
// The theme's focus color is too dark on the backdrop.
|
||||
|
||||
@@ -39,7 +39,7 @@ type MediaControlsOptions struct {
|
||||
}
|
||||
|
||||
// MediaControls are previous, play, next, loop and shuffle buttons.
|
||||
func MediaControls(c *ui.Context, st MediaControlsState, opts MediaControlsOptions) *ui.Element {
|
||||
func MediaControls(c *ui.Context, st MediaControlsState, opts MediaControlsOptions) ui.Element {
|
||||
if opts.OnPrevious == nil || opts.OnPlay == nil || opts.OnPause == nil || opts.OnNext == nil || opts.OnLoop == nil || opts.OnShuffle == nil {
|
||||
panic("mujica: MediaControls needs every callback")
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ type micPeak struct {
|
||||
}
|
||||
|
||||
// MicLevelMeter shows level as segments, held peak and dB.
|
||||
func MicLevelMeter(c *ui.Context, level float32, opts MicLevelMeterOptions) *ui.Element {
|
||||
func MicLevelMeter(c *ui.Context, level float32, opts MicLevelMeterOptions) ui.Element {
|
||||
if level < 0 || level > 1 || math.IsNaN(float64(level)) || opts.Hold < 0 {
|
||||
panic("mujica: MicLevelMeter needs level in 0..1 and Hold >= 0")
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
|
||||
func TestMicLevelMeterPeakHold(t *testing.T) {
|
||||
level := float32(1)
|
||||
var e *ui.Element
|
||||
var desc string
|
||||
tt := ui.NewTester(func(c *ui.Context) {
|
||||
core.Use(c, core.Settings{})
|
||||
e = MicLevelMeter(c, level, MicLevelMeterOptions{Hold: 40 * time.Millisecond})
|
||||
desc = micTestDescription(MicLevelMeter(c, level, MicLevelMeterOptions{Hold: 40 * time.Millisecond}))
|
||||
}, 400, 100)
|
||||
if !tt.HasText("0 dB") {
|
||||
t.Fatalf("texts %v", tt.Texts())
|
||||
@@ -28,18 +28,17 @@ func TestMicLevelMeterPeakHold(t *testing.T) {
|
||||
if r, ok := tt.Find("Microphone level"); !ok || r.W == 0 {
|
||||
t.Fatal("meter not named")
|
||||
}
|
||||
if !strings.Contains(micTestDescription(e), "peak 0 dB") {
|
||||
if !strings.Contains(desc, "peak 0 dB") {
|
||||
t.Fatal("peak not held")
|
||||
}
|
||||
time.Sleep(60 * time.Millisecond)
|
||||
tt.Frame()
|
||||
if !strings.Contains(micTestDescription(e), "peak -20 dB") {
|
||||
tt.Advance(60 * time.Millisecond)
|
||||
if !strings.Contains(desc, "peak -20 dB") {
|
||||
t.Fatal("peak did not fall after the hold")
|
||||
}
|
||||
}
|
||||
|
||||
// micTestDescription rebuilds the meter's spoken value from its state.
|
||||
func micTestDescription(e *ui.Element) string {
|
||||
func micTestDescription(e ui.Element) string {
|
||||
pk := *ui.Local(e, micPeak{}, func() micPeak { return micPeak{} })
|
||||
return "peak " + micDB(pk.level)
|
||||
}
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ type PlaylistOptions struct {
|
||||
|
||||
// PlaylistResult is the playlist's element and this frame's events.
|
||||
type PlaylistResult struct {
|
||||
Element *ui.Element
|
||||
Element ui.Element
|
||||
// Played is the ID chosen by Enter or double click.
|
||||
Played string
|
||||
// Removed is the ID taken out of *items.
|
||||
|
||||
@@ -34,7 +34,7 @@ type ScreenRecorderControlsOptions struct {
|
||||
}
|
||||
|
||||
// ScreenRecorderControls start, pause, resume and stop a recording.
|
||||
func ScreenRecorderControls(c *ui.Context, st RecorderState, opts ScreenRecorderControlsOptions) *ui.Element {
|
||||
func ScreenRecorderControls(c *ui.Context, st RecorderState, opts ScreenRecorderControlsOptions) ui.Element {
|
||||
if opts.OnStart == nil || opts.OnPause == nil || opts.OnResume == nil || opts.OnStop == nil {
|
||||
panic("mujica: ScreenRecorderControls needs every callback")
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ func subtitleRow(c *ui.Context, k theme.Tokens, cues *[]SubtitleCue, s *subtitle
|
||||
u := core.Density(c).Unit()
|
||||
q := &(*cues)[i]
|
||||
changed, removed := false, false
|
||||
row := ui.Column(c).Key(i).Absolute().Left(0).Right(0).Top(float32(i)*rowH).Height(rowH).Padding(u*1.5, u*2).Gap(2).
|
||||
row := ui.Column(c.Key(i)).Absolute().Left(0).Right(0).Top(float32(i)*rowH).Height(rowH).Padding(u*1.5, u*2).Gap(2).
|
||||
BorderWidth(0, 0, 1, 0).BorderColor(k.Border)
|
||||
row.Children(func() {
|
||||
ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Children(func() {
|
||||
|
||||
@@ -42,7 +42,7 @@ type VideoPlayerOptions struct {
|
||||
var VideoBlack = ui.Hex("#0E0C0D")
|
||||
|
||||
// VideoPlayer draws the caller's frame and reports controls through callbacks.
|
||||
func VideoPlayer(c *ui.Context, st VideoState, opts VideoPlayerOptions) *ui.Element {
|
||||
func VideoPlayer(c *ui.Context, st VideoState, opts VideoPlayerOptions) ui.Element {
|
||||
if opts.OnPlay == nil || opts.OnPause == nil || opts.OnSeek == nil {
|
||||
panic("mujica: VideoPlayer needs OnPlay, OnPause and OnSeek")
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func videoStage(c *ui.Context, k theme.Tokens, st VideoState, opts VideoPlayerOp
|
||||
})
|
||||
}
|
||||
|
||||
func videoKeys(stage *ui.Element, st VideoState, opts VideoPlayerOptions) {
|
||||
func videoKeys(stage ui.Element, st VideoState, opts VideoPlayerOptions) {
|
||||
seek := func(d time.Duration) {
|
||||
to := min(max(0, st.Position+d), st.Duration)
|
||||
slog.Debug("mujica: video_player seek", "pos", to)
|
||||
@@ -153,7 +153,7 @@ func videoButtons(c *ui.Context, st VideoState, opts VideoPlayerOptions) {
|
||||
}
|
||||
|
||||
// MediaToggleAction is an iconAction that shows when it is on.
|
||||
func MediaToggleAction(c *ui.Context, icon *ui.SVG, label string, on bool) *ui.Element {
|
||||
func MediaToggleAction(c *ui.Context, icon *ui.SVG, label string, on bool) ui.Element {
|
||||
k := core.Tokens(c)
|
||||
b := core.IconAction(c, icon, label).Role(ui.RoleToggleButton).Selected(on)
|
||||
if on {
|
||||
|
||||
@@ -51,7 +51,7 @@ func VideoScrubber(c *ui.Context, pos *time.Duration, opts VideoScrubberOptions)
|
||||
dur := opts.Duration.Seconds()
|
||||
g, h := input.SliderSetup(0, dur, min(step.Seconds(), dur), nil, false, c)
|
||||
old := *pos
|
||||
var s *ui.Element
|
||||
var s ui.Element
|
||||
var next float64
|
||||
wrap := ui.Box(c).MinWidth(120).Shrink(0).Disabled(opts.Disabled)
|
||||
wrap.Children(func() {
|
||||
|
||||
@@ -94,7 +94,7 @@ func VideoThumbnailStrip(c *ui.Context, current *int, frames []StripFrame, opts
|
||||
|
||||
// stripCell draws one frame and reports a click on it.
|
||||
func stripCell(c *ui.Context, k theme.Tokens, f StripFrame, i int, on bool, fw, fh float32) bool {
|
||||
cell := ui.Box(c).Key(i).Size(fw, fh).Shrink(0).Radius(theme.ControlRadius).Clip().Background(VideoBlack).
|
||||
cell := ui.Box(c.Key(i)).Size(fw, fh).Shrink(0).Radius(theme.ControlRadius).Clip().Background(VideoBlack).
|
||||
Cursor(ui.CursorPointer).AlignSelf(ui.Center)
|
||||
edge, width := k.Border, theme.BorderWidth
|
||||
if on {
|
||||
|
||||
Reference in new issue
Block a user