Add input components 066-085; gallery chrome on real components; deploy warms the edge

This commit is contained in:
ZacharyZhang-NY committed 2026-10-11 19:05:42 -04:00
1 parent 0247a130f5
commit 095eab2b4c
38 files changed
+2340 -172

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
package input
import (
"log/slog"
"github.com/egoist/mygo/ui"
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
)
type ToggleOptions struct {
Size Size
Icon *pixel.Sprite
Disabled bool
// Label names it for assistive technology; zero uses text.
Label string
}
type ToggleResult struct {
Element *ui.Element
Changed bool
}
// Toggle is a button that stays sunken while *on.
func Toggle(c *ui.Context, text string, on *bool, o ToggleOptions) ToggleResult {
k := pixel.K(c)
h, pad, top, sc := o.Size.metrics()
shell, base, st := pixel.Shell(c, func() *ui.Element {
return ui.ToggleBase(c, on).Label(label(o.Label, text)).Disabled(o.Disabled)
})
lead := 0
if o.Icon != nil {
lead = o.Icon.W
if text != "" {
lead += 3
}
}
shell.Size(k.D(pixel.Measure(text)*sc+lead+2*pad), k.D(h)).Draw(func(p *ui.Painter, r ui.Rect) {
g := k.Canvas(p, r)
ink, dy := face(g, Normal, st, *on)
if o.Icon != nil {
g.Sprite(pad, (h-o.Icon.H)/2+dy, o.Icon, 0, ink, 1)
}
g.Text(pad+lead, top+dy, text, ink, sc)
finish(g, st)
})
res := ToggleResult{Element: shell, Changed: base.Changed()}
if res.Changed {
slog.Debug("8bit: toggle", "label", label(o.Label, text), "on", *on)
}
return res
}