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>
42 lines
1.1 KiB
Go
42 lines
1.1 KiB
Go
package feedback
|
|
|
|
import (
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type MeterOptions struct {
|
|
// Min and Max are zero for 0 to 1.
|
|
Min, Max float64
|
|
// Warning and Critical are levels; zero means none.
|
|
Warning, Critical float64
|
|
// Width is in dots; zero means 120.
|
|
Width int
|
|
}
|
|
|
|
// Meter shows a level in Good, Warn or Bad.
|
|
func Meter(c *ui.Context, text string, value float64, o MeterOptions) ui.Element {
|
|
k := pixel.K(c)
|
|
lo, hi := o.Min, o.Max
|
|
if lo == 0 && hi == 0 {
|
|
hi = 1
|
|
}
|
|
if hi <= lo {
|
|
panic("feedback: Meter range is empty")
|
|
}
|
|
w := pixel.Or("Meter Width", o.Width, 120)
|
|
at := func(v float64) int { return 2 + int(max(0, min(1, (v-lo)/(hi-lo)))*float64(w-4)) }
|
|
ink := level(value, o.Warning, o.Critical)
|
|
return ui.Box(c).Role(ui.RoleMeter).Label(text).Description(fmtNum(value)).Size(k.D(w), k.D(10)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Frame(0, 0, w, 10, pixel.Sunken, pixel.Well)
|
|
g.Rect(2, 2, at(value)-2, 6, ink)
|
|
for _, mark := range []float64{o.Warning, o.Critical} {
|
|
if mark != 0 {
|
|
g.VLine(at(mark), 1, 8, pixel.Edge)
|
|
}
|
|
}
|
|
})
|
|
}
|