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>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
// Change is a stat before and after.
|
|
type Change struct {
|
|
Label string
|
|
Old, New int
|
|
}
|
|
|
|
type StatCompareOptions struct{}
|
|
|
|
// StatCompare lists stats old → new with ▲▼ deltas.
|
|
func StatCompare(c *ui.Context, changes []Change, o StatCompareOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
lw, ow, nw, dw := 0, 0, 0, 0
|
|
deltas := make([]string, len(changes))
|
|
for i, ch := range changes {
|
|
switch d := ch.New - ch.Old; {
|
|
case d > 0:
|
|
deltas[i] = "▲" + strconv.Itoa(d)
|
|
case d < 0:
|
|
deltas[i] = "▼" + strconv.Itoa(-d)
|
|
}
|
|
lw = max(lw, pixel.Measure(ch.Label))
|
|
ow = max(ow, pixel.Measure(strconv.Itoa(ch.Old)))
|
|
nw = max(nw, pixel.Measure(strconv.Itoa(ch.New)))
|
|
dw = max(dw, pixel.Measure(deltas[i]))
|
|
}
|
|
arrow := lw + 8 + ow + 4
|
|
newAt := arrow + pixel.Measure("→") + 4
|
|
deltaAt := newAt + nw + 6
|
|
return ui.Column(c).Children(func() {
|
|
for i, ch := range changes {
|
|
delta, ink := deltas[i], pixel.Good
|
|
if ch.New < ch.Old {
|
|
ink = pixel.Bad
|
|
}
|
|
ui.Box(c).Size(k.D(deltaAt+dw), k.D(pixel.LineHeight)).Role(ui.RoleText).
|
|
Label(fmt.Sprintf("%s %d → %d %s", ch.Label, ch.Old, ch.New, delta)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
old, now := strconv.Itoa(ch.Old), strconv.Itoa(ch.New)
|
|
g.Text(0, 0, ch.Label, pixel.Faint, 1)
|
|
g.Text(arrow-4-pixel.Measure(old), 0, old, pixel.Ink, 1)
|
|
g.Text(arrow, 0, "→", pixel.Faint, 1)
|
|
g.Text(newAt+nw-pixel.Measure(now), 0, now, pixel.Ink, 1)
|
|
g.Text(deltaAt, 0, delta, ink, 1)
|
|
})
|
|
}
|
|
})
|
|
}
|