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>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package chart
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type SparklineOptions struct {
|
|
// Width is in dots; zero means 48.
|
|
Width int
|
|
Slot pixel.Slot
|
|
}
|
|
|
|
// Sparkline is a line one text line high, end marked.
|
|
func Sparkline(c *ui.Context, text string, values []float64, o SparklineOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
w := pixel.Or("Sparkline Width", o.Width, 48)
|
|
if len(values) < 2 {
|
|
panic("chart: Sparkline needs two values or more")
|
|
}
|
|
lo, hi := span(values)
|
|
if hi == lo {
|
|
hi = lo + 1
|
|
}
|
|
ink := pick(o.Slot, 0)
|
|
at := func(i int) (int, int) {
|
|
return i * (w - 2) / (len(values) - 1), pixel.LineHeight - 3 - int((values[i]-lo)/(hi-lo)*float64(pixel.LineHeight-6))
|
|
}
|
|
return ui.Box(c).Size(k.D(w), k.D(pixel.LineHeight)).Role(ui.RoleImage).Label(text).Description(nums(values)).Draw(func(pt *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(pt, r)
|
|
for i := 1; i < len(values); i++ {
|
|
x0, y0 := at(i - 1)
|
|
x1, y1 := at(i)
|
|
g.Line(x0, y0, x1, y1, ink)
|
|
}
|
|
x, y := at(len(values) - 1)
|
|
g.Rect(x, y-1, 2, 2, pixel.Accent)
|
|
})
|
|
}
|