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>
77 lines
2.3 KiB
Go
77 lines
2.3 KiB
Go
package chat
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/core"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/icons"
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/MujicaUI/theme"
|
|
)
|
|
|
|
// VoiceWaveformOptions configure a VoiceWaveform.
|
|
type VoiceWaveformOptions struct {
|
|
// Silence sets the quiet threshold; zero means 0.05.
|
|
Silence float32
|
|
// SilentFor sets consecutive quiet samples; zero means 20.
|
|
SilentFor int
|
|
// Width sets waveform width; zero means 200 DIPs.
|
|
Width float32
|
|
}
|
|
|
|
// VoiceWaveform draws recent input levels and a silence hint.
|
|
func VoiceWaveform(c *ui.Context, levels []float32, opts VoiceWaveformOptions) ui.Element {
|
|
if opts.Silence < 0 || opts.Silence >= 1 || opts.SilentFor < 0 || opts.Width < 0 {
|
|
panic("mujica: VoiceWaveform needs 0 <= Silence < 1 and non-negative SilentFor and Width")
|
|
}
|
|
for _, v := range levels {
|
|
if !(v >= 0 && v <= 1) {
|
|
panic("mujica: VoiceWaveform levels must be from 0 to 1")
|
|
}
|
|
}
|
|
silence, need, w := opts.Silence, opts.SilentFor, opts.Width
|
|
if silence == 0 {
|
|
silence = 0.05
|
|
}
|
|
if need == 0 {
|
|
need = 20
|
|
}
|
|
if w == 0 {
|
|
w = 200
|
|
}
|
|
k := core.Tokens(c)
|
|
u := core.Density(c).Unit()
|
|
silent := len(levels) >= need
|
|
for _, v := range levels[max(0, len(levels)-need):] {
|
|
silent = silent && v < silence
|
|
}
|
|
row := ui.Row(c).Gap(u * 2).AlignItems(ui.Center).Shrink(0).Role(ui.RoleMeter).Label(core.Msg(c, "voice_waveform.label"))
|
|
row.Children(func() {
|
|
ui.Box(c).Size(w, 28).Shrink(0).Draw(func(p *ui.Painter, b ui.Rect) {
|
|
n := int((b.W + audioBarGap) / (audioBarWidth + audioBarGap))
|
|
cy := b.Y + b.H/2
|
|
for i := range n {
|
|
// The newest sample sits at the right edge.
|
|
j := len(levels) - n + i
|
|
v := float32(0)
|
|
if j >= 0 {
|
|
v = levels[j]
|
|
}
|
|
h := max(2, v*(b.H-4))
|
|
col := k.AccentText
|
|
if v < silence {
|
|
col = k.TextMuted.Alpha(0.55)
|
|
}
|
|
x := b.X + float32(i)*(audioBarWidth+audioBarGap)
|
|
p.Fill(ui.Rect{X: x, Y: cy - h/2, W: audioBarWidth, H: h}, col, 1)
|
|
}
|
|
})
|
|
if silent {
|
|
ui.Row(c).Gap(u).AlignItems(ui.Center).TextColor(k.Warning).Role(ui.RoleStatus).Children(func() {
|
|
ui.Icon(c, icons.Must("mic-off")).Size(14, 14)
|
|
ui.Text(c, core.Msg(c, "voice_waveform.silent")).FontSize(core.FontSize(c, theme.CaptionSize)).SingleLine()
|
|
})
|
|
}
|
|
})
|
|
return row
|
|
}
|