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>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package navigation
|
|
|
|
import (
|
|
"log/slog"
|
|
|
|
"github.com/egoist/mygo/ui"
|
|
|
|
"git.zacharyzhang.com/ZacharyZhang-NY/8bitMyGoUI/pixel"
|
|
)
|
|
|
|
type BottomNavOptions struct {
|
|
Disabled bool
|
|
}
|
|
|
|
type BottomNavResult struct {
|
|
Element ui.Element
|
|
Changed bool
|
|
}
|
|
|
|
// BottomNav is a bar of labeled icons for narrow screens.
|
|
func BottomNav(c *ui.Context, text string, items []NavItem, selected *int, o BottomNavOptions) BottomNavResult {
|
|
k := pixel.K(c)
|
|
res := BottomNavResult{}
|
|
// The bases turn before they learn they are off.
|
|
v := *selected
|
|
res.Element = ui.RadioGroup(c, func() {
|
|
for i, it := range items {
|
|
shell, _, st := pixel.Shell(c, func() ui.Element {
|
|
return ui.RadioBase(c, &v, i).Label(it.Label).Disabled(o.Disabled)
|
|
})
|
|
w := max(pixel.Measure(it.Label), 12) + 12
|
|
shell.Size(k.D(w), k.D(16+pixel.LineHeight)).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
ink := pixel.Faint
|
|
if i == *selected {
|
|
ink = pixel.Accent
|
|
g.HLine(2, 0, g.W-4, pixel.Accent)
|
|
} else if st.Hover {
|
|
ink = pixel.Ink
|
|
}
|
|
g.Sprite((g.W-it.Icon.W)/2, 2, it.Icon, 0, ink, 1)
|
|
g.Text((g.W-pixel.Measure(it.Label))/2, 14, it.Label, ink, 1)
|
|
g.Finish(st)
|
|
})
|
|
}
|
|
}).Row().Gap(k.D(4)).Padding(k.D(2), k.D(6)).Label(text).Draw(func(p *ui.Painter, r ui.Rect) {
|
|
g := k.Canvas(p, r)
|
|
g.Rect(0, 0, g.W, g.H, pixel.Face)
|
|
g.HLine(0, 0, g.W, pixel.Edge)
|
|
})
|
|
if res.Changed = keep(c, v, selected, o.Disabled); res.Changed {
|
|
slog.Debug("8bit: bottom nav", "label", text, "selected", *selected)
|
|
}
|
|
return res
|
|
}
|