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>
35 lines
978 B
Go
35 lines
978 B
Go
package chart
|
||
|
||
import (
|
||
"fmt"
|
||
"strconv"
|
||
|
||
"github.com/egoist/mygo/ui"
|
||
|
||
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
||
)
|
||
|
||
type ProgressRingOptions struct {
|
||
// Size is the ring's width in dots; zero means 40.
|
||
Size int
|
||
Slot pixel.Slot
|
||
}
|
||
|
||
// ProgressRing fills a ring clockwise from twelve, in pixel arcs.
|
||
func ProgressRing(c *ui.Context, text string, value float64, o ProgressRingOptions) ui.Element {
|
||
k := pixel.K(c)
|
||
if !(value >= 0 && value <= 1) {
|
||
panic(fmt.Sprintf("chart: ProgressRing value %v outside 0–1", value))
|
||
}
|
||
n := pixel.Or("ProgressRing Size", o.Size, 40)
|
||
pct := strconv.Itoa(int(value*100)) + "%"
|
||
ink := pick(o.Slot, 0)
|
||
return ui.Box(c).Size(k.D(n), k.D(n)).Role(ui.RoleProgress).Label(text).Description(pct).Draw(func(p *ui.Painter, r ui.Rect) {
|
||
g := k.Canvas(p, r)
|
||
c, rad := n/2, n/2-1
|
||
sector(g, c, c, rad-4, rad, 0, 1, pixel.Well)
|
||
sector(g, c, c, rad-4, rad, 0, value, ink)
|
||
tiny(g, c-tinyW(pct)/2+1, c-2, pct, pixel.Ink)
|
||
})
|
||
}
|