Files
8bitMyGoUI/chart/winloss.go
T
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

47 lines
1.1 KiB
Go

package chart
import (
"fmt"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type WinLossOptions struct{}
// WinLoss rows blocks: wins up, losses down, draws dashed.
func WinLoss(c *ui.Context, text string, results []int, o WinLossOptions) ui.Element {
k := pixel.K(c)
return ui.Box(c).Size(k.D(len(results)*5), k.D(pixel.LineHeight)).Role(ui.RoleImage).Label(text).
Description(record(results)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
mid := pixel.LineHeight / 2
for i, res := range results {
x := i * 5
switch res {
case 1:
g.Rect(x, mid-6, 4, 5, pixel.Good)
case -1:
g.Rect(x, mid+1, 4, 5, pixel.Bad)
default:
g.Rect(x, mid-1, 4, 2, pixel.Faint)
}
}
})
}
// record is "wins-losses-draws: " then each result, checked.
func record(results []int) string {
var n [3]int
all := make([]float64, len(results))
for i, r := range results {
if r < -1 || r > 1 {
panic(fmt.Sprintf("chart: WinLoss result %d is not -1, 0 or 1", r))
}
n[1-r]++
all[i] = float64(r)
}
return fmt.Sprintf("%d-%d-%d: %s", n[0], n[2], n[1], nums(all))
}